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 {
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user