Skip to content

Commit

Permalink
Add dispatcher::builder
Browse files Browse the repository at this point in the history
Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Jan 6, 2025
1 parent b926e20 commit a112bdd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use ntfy::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Error> {
let dispatcher = DispatcherBuilder::new("https://ntfy.sh")
let dispatcher = dispatcher::builder("https://ntfy.sh")
.credentials(Auth::credentials("username", "password")) // Add optional credentials
.proxy("socks5h://127.0.0.1:9050") // Add optional proxy
.build_async()?; // Build dispatcher
Expand Down
2 changes: 1 addition & 1 deletion examples/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use ntfy::prelude::*;

fn main() -> Result<(), Error> {
let dispatcher = DispatcherBuilder::new("https://ntfy.sh")
let dispatcher = dispatcher::builder("https://ntfy.sh")
.credentials(Auth::credentials("username", "password")) // Add optional credentials
.proxy("socks5://127.0.0.1:9050") // Add optional proxy
.build_blocking()?; // Build dispatcher
Expand Down
2 changes: 1 addition & 1 deletion examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ntfy::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Error> {
let dispatcher = DispatcherBuilder::new("https://ntfy.sh")
let dispatcher = dispatcher::builder("https://ntfy.sh")
.credentials(Auth::credentials("username", "password")) // Add optional credentials
.proxy("socks5h://127.0.0.1:9050") // Add optional proxy
.build_async()?; // Build dispatcher
Expand Down
16 changes: 14 additions & 2 deletions src/dispatcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ use crate::error::Error;
#[cfg(any(feature = "async", feature = "blocking"))]
use crate::payload::Payload;

/// Creates a [`DispatcherBuilder`]
#[inline]
pub fn builder<S>(url: S) -> DispatcherBuilder
where
S: Into<String>,
{
DispatcherBuilder::new(url)
}

#[derive(Debug, Clone)]
pub struct Dispatcher<T>
where
Expand All @@ -34,15 +43,18 @@ where
T: Clone,
{
/// Create new dispatcher
#[deprecated(since = "0.7.0", note = "Please use `Dispatcher::builder` instead")]
#[deprecated(since = "0.7.0", note = "Use the `DispatcherBuilder` instead")]
pub fn new<S>(_url: S, _auth: Option<Auth>, _proxy: Option<S>) -> Result<Self, Error>
where
S: Into<String>,
{
unimplemented!()
}

#[deprecated(since = "0.7.0", note = "Please use `DispatcherBuilder::new` instead")]
#[deprecated(
since = "0.7.0",
note = "Use `dispatcher::builder` or `DispatcherBuilder::new` instead"
)]
pub fn builder<S>(url: S) -> DispatcherBuilder
where
S: Into<String>,
Expand Down

0 comments on commit a112bdd

Please sign in to comment.