implement separated from_uri method

This commit is contained in:
yggverse 2025-01-18 14:15:43 +02:00
parent e4118e1feb
commit de2196e24a

View File

@ -23,24 +23,33 @@ pub enum Request {
impl Request { impl Request {
// Constructors // Constructors
/// Create new `Self` from string /// Create new `Self` from featured string
pub fn parse(query: &str, referrer: Option<Vec<Self>>) -> Result<Self, Error> { pub fn parse(query: &str, referrer: Option<Vec<Self>>) -> Result<Self, Error> {
let (feature, request) = Feature::parse(query); let (feature, request) = Feature::parse(query);
match Uri::parse(request, UriFlags::NONE) { match Uri::parse(request, UriFlags::NONE) {
Ok(uri) => match uri.scheme().as_str() { Ok(uri) => Self::from_uri(uri, Some(feature), referrer),
"gemini" => Ok(Self::Gemini {
feature,
referrer: referrer.unwrap_or_default(),
uri,
}),
"titan" => Ok(Self::Titan(uri)),
_ => Err(Error::Unsupported),
},
Err(e) => Err(Error::Glib(e)), Err(e) => Err(Error::Glib(e)),
} }
} }
/// Create new `Self` from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
pub fn from_uri(
uri: Uri,
feature: Option<Feature>,
referrer: Option<Vec<Self>>,
) -> Result<Self, Error> {
match uri.scheme().as_str() {
"gemini" => Ok(Self::Gemini {
feature: feature.unwrap_or_default(),
referrer: referrer.unwrap_or_default(),
uri,
}),
"titan" => Ok(Self::Titan(uri)),
_ => Err(Error::Unsupported),
}
}
// Actions // Actions
/// Handle `Self` request /// Handle `Self` request