def cast_to(lib, obj, typ):
    """Cast obj to a new type.

    Parameters
    ----------
    lib : CLibrary
        Reference to the library to which the object 'belongs'. This is needed
        as the way to get the address depends on the backend.

    obj :
        Object whose address should be returned.

     type : type or string
        Type object or string which will be used to determine the type of
        the array elements.

    """
    return lib._cast_to(obj, typ)