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

@ -53,10 +53,8 @@ use ggemini::client::{
fn main() -> ExitCode {
Client::new().request_async(
Request::Gemini(
Gemini::build(
Uri::parse("gemini://geminiprotocol.net/", UriFlags::NONE).unwrap()
)
Request::gemini(
Uri::parse(REQUEST, UriFlags::NONE).unwrap(),
),
Priority::DEFAULT,
Cancellable::new(),

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)

View file

@ -1,15 +1,18 @@
use gio::*;
use glib::*;
use ggemini::client::connection::request::Gemini;
use ggemini::client::connection::Request;
#[test]
fn client_connection_request_gemini_build() {
fn client_connection_request_gemini() {
const REQUEST: &str = "gemini://geminiprotocol.net/";
let request = Gemini::build(Uri::parse(REQUEST, UriFlags::NONE).unwrap());
assert_eq!(&request.uri.to_string(), REQUEST);
assert_eq!(
&match Request::gemini(Uri::parse(REQUEST, UriFlags::NONE).unwrap()) {
Request::Gemini(request) => request.uri.to_string(),
Request::Titan(_) => panic!(),
},
REQUEST
);
}
// @TODO