url_pest_parser

Crates.iourl_pest_parser
lib.rsurl_pest_parser
version0.1.0
sourcesrc
created_at2024-11-06 23:10:58.570239
updated_at2024-11-06 23:10:58.570239
descriptionA URL parser using pest for Rust.
homepage
repository
max_upload_size
id1439304
size19,434
Andrii Negrub (0LuminaX0)

documentation

README

URL Parser

A Rust-based URL parser using the pest parsing library with ability to extract various components like protocol, domain, subdomain, port, path segments, query parameters, and fragments.

Parsing Logic

The grammar is defined using pest and covers the following components:

  • Protocol: Either "http" or "https".
  • Subdomain: Optional subdomain that appears before the main domain.
  • Domain: The main domain name.
  • Port: Optional port number, appearing after a colon.
  • Path: Segmented by /, representing directories or resources.
  • Query Parameters: Key-value pairs in the query string, separated by &.
  • Fragment: The portion of the URL following a #.

How It Works

The parser processes URLs by breaking them into components using predefined grammar. Then the results are encapsulated in a structured ParsedURL object.

Example

protocol://subdomain.domain:port/path/to/resource?param1=value1&param2=value2#section
   └── protocol = "https"
   └── subdomain = "sub"
   └── domain = "example.com"
   └── port = 8080
   └── path = ["path", "to", "resource"]
   └── query = [("param1", "value1"), ("param2", "value2")]
   └── fragment = "section"
Commit count: 0

cargo fmt