implement Request constructors, remove build methods

This commit is contained in:
yggverse 2025-01-13 23:14:54 +02:00
parent e2097138a9
commit ce5d3ac4d2
5 changed files with 29 additions and 29 deletions

View file

@ -7,6 +7,7 @@ pub use gemini::Gemini;
pub use titan::Titan;
use gio::NetworkAddress;
use glib::Uri;
/// Single `Request` implementation for different protocols
pub enum Request {
@ -15,6 +16,23 @@ pub enum Request {
}
impl Request {
// Constructors
/// Create new `Self` for [Gemini protocol](https://geminiprotocol.net)
pub fn gemini(uri: Uri) -> Self {
Self::Gemini(Gemini { uri })
}
/// Create new `Self` for [Titan protocol](gemini://transjovian.org/titan/page/The%20Titan%20Specification)
pub fn titan(uri: Uri, mime: String, token: Option<String>, data: Vec<u8>) -> Self {
Self::Titan(Titan {
uri,
mime,
token,
data,
})
}
// Getters
/// Get [NetworkAddress](https://docs.gtk.org/gio/class.NetworkAddress.html) for `Self`

View file

@ -6,13 +6,6 @@ pub struct Gemini {
}
impl Gemini {
// Constructors
/// Build valid new `Self`
pub fn build(uri: Uri) -> Self {
Self { uri } // @TODO validate
}
// Getters
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)

View file

@ -9,18 +9,6 @@ pub struct Titan {
}
impl Titan {
// Constructors
/// Build valid new `Self`
pub fn build(uri: Uri, mime: String, token: Option<String>, data: Vec<u8>) -> Self {
Self {
uri,
mime,
token,
data,
} // @TODO validate
}
// Getters
/// Copy `Self` to [Bytes](https://docs.gtk.org/glib/struct.Bytes.html)