mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
implement separated from_uri
method
This commit is contained in:
parent
e4118e1feb
commit
de2196e24a
@ -23,24 +23,33 @@ pub enum Request {
|
||||
impl Request {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self` from string
|
||||
/// Create new `Self` from featured string
|
||||
pub fn parse(query: &str, referrer: Option<Vec<Self>>) -> Result<Self, Error> {
|
||||
let (feature, request) = Feature::parse(query);
|
||||
|
||||
match Uri::parse(request, UriFlags::NONE) {
|
||||
Ok(uri) => match uri.scheme().as_str() {
|
||||
"gemini" => Ok(Self::Gemini {
|
||||
feature,
|
||||
referrer: referrer.unwrap_or_default(),
|
||||
uri,
|
||||
}),
|
||||
"titan" => Ok(Self::Titan(uri)),
|
||||
_ => Err(Error::Unsupported),
|
||||
},
|
||||
Ok(uri) => Self::from_uri(uri, Some(feature), referrer),
|
||||
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
|
||||
|
||||
/// Handle `Self` request
|
||||
|
Loading…
x
Reference in New Issue
Block a user