def cast(buf, V, wordsize=None):
    """
    apply a vstruct class to a sequence of bytes.

    Args:
        buf (bytes): the bytes to parse.
        V (type[vstruct.VStruct]): the vstruct class.

    Returns:
        V: the parsed instance of V.

    Example::

        s = cast(buf, Stat)
        assert s.gid == 0x1000
    """
    v = V(wordsize=wordsize)
    v.vsParse(buf)
    return v