def _rgb_to_hex_string(rgb: tuple) -> str:
    """Convert RGB tuple to hex string."""
    def clamp(x):
        return max(0, min(x, 255))
    return "#{0:02x}{1:02x}{2:02x}".format(clamp(rgb[0]),
                                           clamp(rgb[1]),
                                           clamp(rgb[2]))