config: custom deserializer for nickname
It looks like the current toml crate doesn't allow borrowed strings? See https://gitlab.com/xmpp-rs/xmpp-rs/-/merge_requests/638. This is happening after xmpp-rs' 60bf821c63. Signed-off-by: pep <pep@bouah.net>
This commit is contained in:
parent
8dfb89fe38
commit
72a3e5a188
1 changed files with 12 additions and 1 deletions
|
|
@ -18,7 +18,7 @@ use std::net::{IpAddr, Ipv6Addr, SocketAddr};
|
||||||
|
|
||||||
use camino::{Utf8Path, Utf8PathBuf};
|
use camino::{Utf8Path, Utf8PathBuf};
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use xmpp::jid::{BareJid, ResourcePart};
|
use xmpp::jid::{BareJid, ResourcePart};
|
||||||
|
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
|
|
@ -41,6 +41,7 @@ pub struct Config {
|
||||||
|
|
||||||
/// Nickname to use in rooms
|
/// Nickname to use in rooms
|
||||||
#[serde(default = "Config::default_nickname")]
|
#[serde(default = "Config::default_nickname")]
|
||||||
|
#[serde(deserialize_with = "Config::owned_nickname")]
|
||||||
pub nickname: ResourcePart,
|
pub nickname: ResourcePart,
|
||||||
|
|
||||||
/// Secret that matches the one provided to the Webhook service
|
/// Secret that matches the one provided to the Webhook service
|
||||||
|
|
@ -57,6 +58,16 @@ impl Config {
|
||||||
ResourcePart::new("cusku").unwrap().into()
|
ResourcePart::new("cusku").unwrap().into()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn owned_nickname<'de, D>(deserializer: D) -> Result<ResourcePart, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = String::deserialize(deserializer)?;
|
||||||
|
Ok(ResourcePart::new(&s)
|
||||||
|
.map_err(serde::de::Error::custom)?
|
||||||
|
.into_owned())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn default_addr() -> SocketAddr {
|
pub fn default_addr() -> SocketAddr {
|
||||||
SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 3000)
|
SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 3000)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue