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_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
Cookieheader. - CssDeclaration
- A lightweight CSS declaration.
- CssRule
- A lightweight CSS rule.
- Header
- A simple header name-value pair.
- Html
Attribute - A lightweight HTML attribute.
- Html
Element - A lightweight HTML element view.
- Html
Heading - A lightweight heading extracted from
h1throughh6. - Html
Link - A lightweight link extracted from an anchor tag.
- Http
Request Line - A parsed HTTP request line.
- Http
Status - A common HTTP status code and its standard reason phrase.
- Http
Status Line - A parsed HTTP status line.
- Mime
Type - A lightweight MIME type split into type, subtype, and optional suffix.
- Origin
- A lightweight web origin.
- Query
Param - A parsed query parameter with an optional value.
- Route
Param - A captured route parameter.
- Route
Segment - A normalized route segment.
- SetCookie
- A lightweight view of a
Set-Cookieheader. - UriParts
- Basic URI parts extracted with lightweight string splitting.
- UrlParts
- Lightweight URL parts extracted with simple string splitting.
Enums§
- Http
Method - Known HTTP methods plus a variant for valid extension methods.
- Http
Version - A small set of HTTP versions commonly encountered in textual protocol surfaces.
- Status
Class - A broad HTTP status code class.
Functions§
- append_
query_ param - Appends a key-value pair to the query string.
- build_
cookie_ header - Builds a
Cookieheader string from cookie pairs. - build_
query - Builds a query string from ordered parameters.
- cookie_
name_ is_ valid - Returns
truewhen 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
hrefattributes. - 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
truewhen the header contains the requested cookie. - has_
header - Returns
truewhen the header list contains the requested name. - has_
query_ param - Returns
truewhen the query contains the requested key. - has_
scheme - Returns
truewhen the input begins with a valid URI scheme. - is_
absolute_ route - Returns
truewhen the route is absolute. - is_
cacheable_ by_ default - Returns
truefor codes that are cacheable by default in common HTTP semantics. - is_
client_ error - Returns
truewhen the code is a client error. - is_
css_ color_ value - Returns
truewhen the input looks like a common CSS color value. - is_
css_ custom_ property - Returns
truewhen the input looks like a CSS custom property. - is_
css_ identifier - Returns
truewhen the input looks like a CSS identifier. - is_
css_ length_ value - Returns
truewhen the input looks like a common CSS length value. - is_
css_ mime - Returns
truewhen the MIME type is CSS. - is_
error - Returns
truewhen the code is a client or server error. - is_
html_ mime - Returns
truewhen the MIME type is HTML. - is_
http_ url - Returns
truewhen the input is an HTTP URL. - is_
http_ version - Returns
truewhen the input is a recognized textual HTTP version. - is_
https_ url - Returns
truewhen the input is an HTTPS URL. - is_
idempotent_ method - Returns
truewhen the method is defined as idempotent. - is_
image_ mime - Returns
truewhen the MIME type is image-based. - is_
informational - Returns
truewhen the code is informational. - is_
json_ mime - Returns
truewhen the MIME type is JSON or a+jsonsubtype. - is_
redirect - Returns
truewhen the code is a redirect. - is_
request_ target_ absolute_ form - Returns
truewhen the target is in absolute-form, such ashttps://example.com/. - is_
request_ target_ asterisk_ form - Returns
truewhen the target is the asterisk-form*. - is_
request_ target_ authority_ form - Returns
truewhen the target is in authority-form, such asexample.com:443. - is_
request_ target_ origin_ form - Returns
truewhen the target is in origin-form, such as/items?limit=10. - is_
safe_ method - Returns
truewhen the method is defined as safe. - is_
secure_ origin - Returns
truefor secure-origin schemes. - is_
server_ error - Returns
truewhen the code is a server error. - is_
standard_ method - Returns
truewhen the token is one of the standard request methods. - is_
success - Returns
truewhen the code is successful. - is_
text_ mime - Returns
truewhen the MIME type is text-based. - is_
valid_ header_ name - Returns
truewhen the input is a valid HTTP field name. - is_
xml_ mime - Returns
truewhen the MIME type is XML or a+xmlsubtype. - join_
routes - Joins two route fragments with exactly one slash.
- looks_
like_ css - Returns
truewhen the input looks like CSS markup or a declaration. - looks_
like_ html - Returns
truewhen the input contains tag-like HTML markup. - looks_
like_ http_ request_ line - Returns
truewhen the input looks like a valid HTTP request line. - looks_
like_ http_ status_ line - Returns
truewhen the input looks like a valid HTTP status line. - looks_
like_ mime - Returns
truewhen the input parses as a MIME type. - looks_
like_ uri - Returns
truewhen the input starts with a valid URI scheme or authority marker. - looks_
like_ url - Returns
truewhen the input looks like a parsable absolute URL. - matches_
route_ pattern - Returns
truewhen a simple:parampattern matches the path. - method_
allows_ body - Returns
truewhen the method can reasonably carry a body. - method_
expects_ body - Returns
truewhen 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
Cookieheader into cookie pairs. - parse_
header_ line - Parses a single
Name: Valueheader 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-Cookieheader. - 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
truewhen both inputs resolve to the same origin. - set_
header - Sets or replaces a header value.
- split_
css_ declaration - Splits a
property: valuedeclaration. - 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.