code: def to_hex(
      primitive: Primitives = None, hexstr: HexStr = None, text: str = None
  ) -> HexStr:
      
      if hexstr is not None:
          return HexStr(add_0x_prefix(hexstr.lower()))
  
      if text is not None:
          return HexStr(encode_hex(text.encode("utf-8")))
  
      if is_boolean(primitive):
          return HexStr("0x1") if primitive else HexStr("0x0")
  
      if isinstance(primitive, (bytes, bytearray)):
          return HexStr(encode_hex(primitive))
      elif is_string(primitive):
          raise TypeError(
              "Unsupported type: The primitive argument must be one of: bytes,"
              "bytearray, int or bool and not str"
          )
  
      if is_integer(primitive):
          return HexStr(hex(cast(int, primitive)))
  
      raise TypeError(
          "Unsupported type: '{0}'.  Must be one of: bool, str, bytes, bytearray"
          "or int.".format(repr(type(primitive)))
      )
docs: Auto converts any supported value into its hex representation.
      Trims leading zeros, as defined in:
      https://github.com/ethereum/wiki/wiki/JSON-RPC#hex-value-encoding