def format_path(path, modules_only):
    """
    Formats Rust paths.
    :param path: A Rust path delimited by `::`
    :param modules_only: Whether to cut off the last component of the path
    :return:
    """
    if modules_only:
        path = path.split('::')
        if len(path[-1]) == 0 or path[-1][0].isupper():
            path.pop()
        path = '::'.join(path)
    return path