Skip to main content

Crate use_web

Crate use_web 

Source
Expand description

§use-web

Feature-gated facade crate for the focused RustUse web primitives.

§Experimental

use-web is experimental while the workspace remains below 0.3.0. Expect small API adjustments during the first release wave.

§Example

use use_web::{parse_url_basic, reason_phrase};

let parts = parse_url_basic("https://example.com/docs?page=2#intro").unwrap();

assert_eq!(parts.host.as_deref(), Some("example.com"));
assert_eq!(reason_phrase(404), Some("Not Found"));
assert_eq!(use_web::html::extract_title("<title>Docs</title>").as_deref(), Some("Docs"));

§Scope

  • Thin re-exports over the focused crates in this workspace.
  • Feature flags that map directly to the child crates.
  • One dependency when consumer ergonomics matter more than the narrowest possible dependency graph.

§Non-goals

  • A second abstraction layer over the focused crates.
  • Framework behavior, networking, or browser runtime logic.
  • JavaScript language utilities.

§License

Licensed under either of the following, at your option:

  • Apache License, Version 2.0
  • MIT license

Re-exports§

pub use use_http as http;
pub use use_method as method;
pub use use_header as header;
pub use use_status as status;
pub use use_cookie as cookie;
pub use use_mime as mime;
pub use use_uri as uri;
pub use use_url as url;
pub use use_query as query;
pub use use_origin as origin;
pub use use_route as route;
pub use use_html as html;
pub use use_css as css;

Structs§

Cookie
A cookie name-value pair from the Cookie header.
CssDeclaration
A lightweight CSS declaration.
CssRule
A lightweight CSS rule.
Header
A simple header name-value pair.
HtmlAttribute
A lightweight HTML attribute.
HtmlElement
A lightweight HTML element view.
HtmlHeading
A lightweight heading extracted from h1 through h6.
HtmlLink
A lightweight link extracted from an anchor tag.
HttpRequestLine
A parsed HTTP request line.
HttpStatus
A common HTTP status code and its standard reason phrase.
HttpStatusLine
A parsed HTTP status line.
MimeType
A lightweight MIME type split into type, subtype, and optional suffix.
Origin
A lightweight web origin.
QueryParam
A parsed query parameter with an optional value.
RouteParam
A captured route parameter.
RouteSegment
A normalized route segment.
SetCookie
A lightweight view of a Set-Cookie header.
UriParts
Basic URI parts extracted with lightweight string splitting.
UrlParts
Lightweight URL parts extracted with simple string splitting.

Enums§

HttpMethod
Known HTTP methods plus a variant for valid extension methods.
HttpVersion
A small set of HTTP versions commonly encountered in textual protocol surfaces.
StatusClass
A broad HTTP status code class.

Functions§

append_query_param
Appends a key-value pair to the query string.
build_cookie_header
Builds a Cookie header string from cookie pairs.
build_query
Builds a query string from ordered parameters.
cookie_name_is_valid
Returns true when the cookie name uses a conservative HTTP token character set.
default_port_for_scheme
Returns the conventional default port for a scheme.
ensure_trailing_slash
Ensures that the URL or path ends with a trailing slash before any query or fragment.
escape_html
Escapes common HTML-sensitive characters.
extension_from_mime
Returns a common extension for the requested MIME type.
extract_attributes
Extracts attributes from an opening tag.
extract_css_declarations
Extracts declarations from a CSS block or declaration list.
extract_fragment
Extracts the fragment without the leading # when present.
extract_headings
Extracts heading tags in document order.
extract_host
Extracts the URL host when available.
extract_links
Extracts anchor tags with href attributes.
extract_meta_content
Extracts a <meta name="..." content="..."> value.
extract_origin
Extracts the origin portion from a URL or origin-like string.
extract_path
Extracts the URL path when available.
extract_port
Extracts the URL port when available.
extract_query
Extracts the query without the leading ? and excluding any fragment.
extract_route_params
Extracts named route parameters when a pattern matches.
extract_scheme
Extracts a lowercase URI scheme when the input starts with one.
extract_title
Extracts the title text from the first <title> tag.
format_http_version
Formats an HTTP version token.
format_origin
Formats an origin as scheme://host[:port].
get_attribute
Returns the named attribute value from an element when present.
get_cookie
Returns the first cookie value with the requested name.
get_header
Returns the first matching header value, compared case-insensitively.
get_query_param
Returns the first value for the requested key.
has_cookie
Returns true when the header contains the requested cookie.
has_header
Returns true when the header list contains the requested name.
has_query_param
Returns true when the query contains the requested key.
has_scheme
Returns true when the input begins with a valid URI scheme.
is_absolute_route
Returns true when the route is absolute.
is_cacheable_by_default
Returns true for codes that are cacheable by default in common HTTP semantics.
is_client_error
Returns true when the code is a client error.
is_css_color_value
Returns true when the input looks like a common CSS color value.
is_css_custom_property
Returns true when the input looks like a CSS custom property.
is_css_identifier
Returns true when the input looks like a CSS identifier.
is_css_length_value
Returns true when the input looks like a common CSS length value.
is_css_mime
Returns true when the MIME type is CSS.
is_error
Returns true when the code is a client or server error.
is_html_mime
Returns true when the MIME type is HTML.
is_http_url
Returns true when the input is an HTTP URL.
is_http_version
Returns true when the input is a recognized textual HTTP version.
is_https_url
Returns true when the input is an HTTPS URL.
is_idempotent_method
Returns true when the method is defined as idempotent.
is_image_mime
Returns true when the MIME type is image-based.
is_informational
Returns true when the code is informational.
is_json_mime
Returns true when the MIME type is JSON or a +json subtype.
is_redirect
Returns true when the code is a redirect.
is_request_target_absolute_form
Returns true when the target is in absolute-form, such as https://example.com/.
is_request_target_asterisk_form
Returns true when the target is the asterisk-form *.
is_request_target_authority_form
Returns true when the target is in authority-form, such as example.com:443.
is_request_target_origin_form
Returns true when the target is in origin-form, such as /items?limit=10.
is_safe_method
Returns true when the method is defined as safe.
is_secure_origin
Returns true for secure-origin schemes.
is_server_error
Returns true when the code is a server error.
is_standard_method
Returns true when the token is one of the standard request methods.
is_success
Returns true when the code is successful.
is_text_mime
Returns true when the MIME type is text-based.
is_valid_header_name
Returns true when the input is a valid HTTP field name.
is_xml_mime
Returns true when the MIME type is XML or a +xml subtype.
join_routes
Joins two route fragments with exactly one slash.
looks_like_css
Returns true when the input looks like CSS markup or a declaration.
looks_like_html
Returns true when the input contains tag-like HTML markup.
looks_like_http_request_line
Returns true when the input looks like a valid HTTP request line.
looks_like_http_status_line
Returns true when the input looks like a valid HTTP status line.
looks_like_mime
Returns true when the input parses as a MIME type.
looks_like_uri
Returns true when the input starts with a valid URI scheme or authority marker.
looks_like_url
Returns true when the input looks like a parsable absolute URL.
matches_route_pattern
Returns true when a simple :param pattern matches the path.
method_allows_body
Returns true when the method can reasonably carry a body.
method_expects_body
Returns true when the method usually implies a request body.
mime_from_extension
Returns a common MIME type for the requested extension.
minify_css_basic
Performs a small whitespace-oriented CSS minification pass.
normalize_css_property
Normalizes a CSS property to lowercase ASCII.
normalize_header_name
Normalizes a header name to lowercase ASCII.
normalize_method
Normalizes a valid HTTP method token to uppercase.
normalize_route
Normalizes repeated slashes and removes trailing slashes except for the root route.
parse_cookie_header
Parses a Cookie header into cookie pairs.
parse_header_line
Parses a single Name: Value header line.
parse_headers
Parses multiple header lines separated by newlines.
parse_http_version
Parses a textual HTTP version token.
parse_method
Parses a method token into a standard variant or Other.
parse_mime
Parses a MIME type essence into simple parts.
parse_origin
Parses a strict origin string without path, query, or fragment content.
parse_query
Parses a query string into ordered key-value pairs.
parse_request_line
Parses a request line in the form METHOD target HTTP/x.
parse_set_cookie_basic
Parses a lightweight Set-Cookie header.
parse_status_line
Parses a status line in the form HTTP/x 200 Reason.
parse_uri_basic
Parses URI-like input with lightweight splitting and graceful fallback behavior.
parse_url_basic
Parses a URL with lightweight string splitting.
reason_phrase
Returns the standard reason phrase for a common status code.
remove_fragment
Removes the fragment portion from a URL.
remove_header
Removes every header whose name matches case-insensitively.
remove_query
Removes the query portion and preserves any fragment.
remove_query_param
Removes every matching key from the query string.
route_depth
Returns the number of non-empty route segments.
same_origin
Returns true when both inputs resolve to the same origin.
set_header
Sets or replaces a header value.
split_css_declaration
Splits a property: value declaration.
split_route
Splits a route into normalized segments.
status_class
Returns the broad HTTP status class for a code in the standard range.
strip_css_comments
Removes CSS comments from the input.
strip_fragment
Returns the input without the fragment portion.
strip_html_comments
Removes HTML comments from the input.
strip_query
Returns the input without the query portion.
strip_tags_basic
Removes tag-like markup with simple angle-bracket stripping.
strip_trailing_slash
Removes trailing slashes before any query or fragment.
unescape_html
Unescapes common HTML entities.