mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-04-01 01:25:32 +00:00
implement Uri reference getter
This commit is contained in:
parent
ea9d7e4c5d
commit
caa61bb808
1 changed files with 13 additions and 8 deletions
|
|
@ -6,7 +6,10 @@ pub use error::Error;
|
||||||
pub use gemini::Gemini;
|
pub use gemini::Gemini;
|
||||||
pub use titan::Titan;
|
pub use titan::Titan;
|
||||||
|
|
||||||
|
// Local dependencies
|
||||||
|
|
||||||
use gio::NetworkAddress;
|
use gio::NetworkAddress;
|
||||||
|
use glib::Uri;
|
||||||
|
|
||||||
/// Single `Request` implementation for different protocols
|
/// Single `Request` implementation for different protocols
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
|
|
@ -17,7 +20,7 @@ pub enum Request {
|
||||||
impl Request {
|
impl Request {
|
||||||
// Getters
|
// Getters
|
||||||
|
|
||||||
/// Get header string for `Self`
|
/// Generate header string for `Self`
|
||||||
pub fn header(&self) -> String {
|
pub fn header(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::Gemini(ref this) => this.header(),
|
Self::Gemini(ref this) => this.header(),
|
||||||
|
|
@ -25,15 +28,17 @@ impl Request {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get reference to `Self` [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||||
|
pub fn uri(&self) -> &Uri {
|
||||||
|
match self {
|
||||||
|
Self::Gemini(ref this) => &this.uri,
|
||||||
|
Self::Titan(ref this) => &this.uri,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) for `Self`
|
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) for `Self`
|
||||||
pub fn to_network_address(&self, default_port: u16) -> Result<NetworkAddress, Error> {
|
pub fn to_network_address(&self, default_port: u16) -> Result<NetworkAddress, Error> {
|
||||||
match crate::gio::network_address::from_uri(
|
match crate::gio::network_address::from_uri(self.uri(), default_port) {
|
||||||
&match self {
|
|
||||||
Self::Gemini(ref request) => request.uri.clone(),
|
|
||||||
Self::Titan(ref request) => request.uri.clone(),
|
|
||||||
},
|
|
||||||
default_port,
|
|
||||||
) {
|
|
||||||
Ok(network_address) => Ok(network_address),
|
Ok(network_address) => Ok(network_address),
|
||||||
Err(e) => Err(Error::NetworkAddress(e)),
|
Err(e) => Err(Error::NetworkAddress(e)),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue