fist/extract
Types
Represents an error encountered while attempting to extract or parse a parameter.
pub type ExtractError {
NotFound(key: String)
InvalidFormat(key: String, raw_value: String, expected: String)
}
Constructors
-
NotFound(key: String)The specified key was not found in the parameters or query dictionary.
-
InvalidFormat(key: String, raw_value: String, expected: String)The parameter was found, but failed type conversion to the expected format.
Values
pub fn bool(
from params: dict.Dict(String, String),
key key: String,
) -> Result(Bool, ExtractError)
Extracts and parses a boolean parameter from a dictionary.
Recognizes “true”, “1”, “yes”, “t” as True and “false”, “0”, “no”, “f” as False (case-insensitive).
pub fn bool_or(
from params: dict.Dict(String, String),
key key: String,
default default_val: Bool,
) -> Bool
Returns the parsed boolean value for key, or default if missing or malformed.
pub fn custom(
from params: dict.Dict(String, String),
key key: String,
expected expected_name: String,
parser parse_fn: fn(String) -> Result(a, Nil),
) -> Result(a, ExtractError)
Extracts a parameter and applies a custom parser function.
pub fn error_to_string(error: ExtractError) -> String
Converts an ExtractError into a standardized, human-readable error description.
pub fn float(
from params: dict.Dict(String, String),
key key: String,
) -> Result(Float, ExtractError)
Extracts and parses a floating-point number from a dictionary.
Returns Error(NotFound(key)) if missing, or Error(InvalidFormat(key, val, "float"))
if parsing fails.
pub fn int(
from params: dict.Dict(String, String),
key key: String,
) -> Result(Int, ExtractError)
Extracts and parses an integer parameter from a dictionary.
Returns Error(NotFound(key)) if missing, or Error(InvalidFormat(key, val, "integer"))
if parsing fails.
pub fn int_or(
from params: dict.Dict(String, String),
key key: String,
default default_val: Int,
) -> Int
Returns the parsed integer value for key, or default if missing or malformed.
pub fn non_empty_string(
from params: dict.Dict(String, String),
key key: String,
) -> Result(String, ExtractError)
Extracts a non-empty string parameter from a dictionary.
Returns Error(NotFound(key)) if the key is missing, or
Error(InvalidFormat(key, val, "non-empty string")) if the trimmed value is empty.
pub fn optional_bool(
from params: dict.Dict(String, String),
key key: String,
) -> Result(option.Option(Bool), ExtractError)
Extracts an optional boolean. Returns Ok(None) if missing, Ok(Some(Bool)) if valid,
or Error(InvalidFormat) if present but malformed.
pub fn optional_float(
from params: dict.Dict(String, String),
key key: String,
) -> Result(option.Option(Float), ExtractError)
Extracts an optional float. Returns Ok(None) if missing, Ok(Some(Float)) if valid,
or Error(InvalidFormat) if present but malformed.
pub fn optional_int(
from params: dict.Dict(String, String),
key key: String,
) -> Result(option.Option(Int), ExtractError)
Extracts an optional integer. Returns Ok(None) if missing, Ok(Some(Int)) if valid,
or Error(InvalidFormat) if present but malformed.
pub fn optional_string(
from params: dict.Dict(String, String),
key key: String,
) -> option.Option(String)
Extracts an optional string. Returns None if the key is missing.
pub fn optional_uuid(
from params: dict.Dict(String, String),
key key: String,
) -> Result(option.Option(String), ExtractError)
Extracts an optional UUID. Returns Ok(None) if missing, Ok(Some(UUID)) if valid,
or Error(InvalidFormat) if present but malformed.
pub fn query_bool(
from request: request.Request(a),
key key: String,
) -> Result(Bool, ExtractError)
Extracts and parses a boolean query parameter from a request.
pub fn query_int(
from request: request.Request(a),
key key: String,
) -> Result(Int, ExtractError)
Extracts and parses an integer query parameter from a request.
pub fn query_params(
request: request.Request(a),
) -> dict.Dict(String, String)
Parses query parameters from a Request into a dictionary.
Returns an empty dictionary if the request has no query string.
pub fn query_string(
from request: request.Request(a),
key key: String,
) -> Result(String, ExtractError)
Extracts a string query parameter from a request.
pub fn require_bool(
from params: dict.Dict(String, String),
key key: String,
or on_error: fn(ExtractError) -> output,
apply next: fn(Bool) -> output,
) -> output
Ergonomic extractor for use syntax requiring a boolean parameter.
pub fn require_custom(
from params: dict.Dict(String, String),
key key: String,
expected expected_name: String,
parser parse_fn: fn(String) -> Result(a, Nil),
or on_error: fn(ExtractError) -> output,
apply next: fn(a) -> output,
) -> output
Ergonomic extractor for use syntax requiring a custom parsed type.
pub fn require_float(
from params: dict.Dict(String, String),
key key: String,
or on_error: fn(ExtractError) -> output,
apply next: fn(Float) -> output,
) -> output
Ergonomic extractor for use syntax requiring a float parameter.
pub fn require_int(
from params: dict.Dict(String, String),
key key: String,
or on_error: fn(ExtractError) -> output,
apply next: fn(Int) -> output,
) -> output
Ergonomic extractor for use syntax requiring an integer parameter.
pub fn require_non_empty_string(
from params: dict.Dict(String, String),
key key: String,
or on_error: fn(ExtractError) -> output,
apply next: fn(String) -> output,
) -> output
Ergonomic extractor for use syntax requiring a non-empty string parameter.
pub fn require_string(
from params: dict.Dict(String, String),
key key: String,
or on_error: fn(ExtractError) -> output,
apply next: fn(String) -> output,
) -> output
Ergonomic extractor for use syntax requiring a string parameter.
pub fn require_uuid(
from params: dict.Dict(String, String),
key key: String,
or on_error: fn(ExtractError) -> output,
apply next: fn(String) -> output,
) -> output
Ergonomic extractor for use syntax requiring a valid RFC 4122 UUID.
pub fn string(
from params: dict.Dict(String, String),
key key: String,
) -> Result(String, ExtractError)
Extracts a string parameter from a dictionary.
Returns Error(NotFound(key)) if the key is missing.
pub fn string_or(
from params: dict.Dict(String, String),
key key: String,
default default_val: String,
) -> String
Returns the string value for key, or default if the key does not exist.
pub fn uuid(
from params: dict.Dict(String, String),
key key: String,
) -> Result(String, ExtractError)
Extracts and validates an RFC 4122 standard UUID (e.g. “123e4567-e89b-12d3-a456-426614174000”).
Returns lowercase normalized UUID string on success, or InvalidFormat on failure.