mirror of
https://github.com/YGGverse/ggemini.git
synced 2026-03-31 17:15:31 +00:00
delegate from_uri method to gio::network_address wrapper
This commit is contained in:
parent
239786da6a
commit
5737b89278
4 changed files with 35 additions and 22 deletions
24
src/gio/network_address.rs
Normal file
24
src/gio/network_address.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
pub mod error;
|
||||
pub use error::Error;
|
||||
|
||||
use gio::NetworkAddress;
|
||||
use glib::Uri;
|
||||
|
||||
/// Create new valid [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) from [Uri](https://docs.gtk.org/glib/struct.Uri.html)
|
||||
///
|
||||
/// Useful as:
|
||||
/// * shared [SocketConnectable](https://docs.gtk.org/gio/iface.SocketConnectable.html) interface
|
||||
/// * [SNI](https://geminiprotocol.net/docs/protocol-specification.gmi#server-name-indication) record for TLS connections
|
||||
pub fn from_uri(uri: &Uri, default_port: u16) -> Result<NetworkAddress, Error> {
|
||||
Ok(NetworkAddress::new(
|
||||
&match uri.host() {
|
||||
Some(host) => host,
|
||||
None => return Err(Error::Host(uri.to_string())),
|
||||
},
|
||||
if uri.port().is_positive() {
|
||||
uri.port() as u16
|
||||
} else {
|
||||
default_port
|
||||
},
|
||||
))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue