Skip to content

Commit

Permalink
Rename new_{aci,pni} to from_{aci,pni}
Browse files Browse the repository at this point in the history
This is more according to Rust convention regarding constructors
  • Loading branch information
rubdos committed Oct 12, 2024
1 parent 6b97681 commit e69ace5
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions libsignal-service/src/service_address.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::convert::TryFrom;

use libsignal_protocol::{DeviceId, ProtocolAddress};
use libsignal_protocol::{DeviceId, ProtocolAddress, ServiceId};
use uuid::Uuid;

pub use crate::push_service::ServiceIdType;
Expand Down Expand Up @@ -48,14 +48,24 @@ impl ServiceAddress {
}
}

#[deprecated]
pub fn new_aci(uuid: Uuid) -> Self {
Self::from_aci(uuid)
}

pub fn from_aci(uuid: Uuid) -> Self {
Self {
uuid,
identity: ServiceIdType::AccountIdentity,
}
}

#[deprecated]
pub fn new_pni(uuid: Uuid) -> Self {
Self::from_pni(uuid)
}

pub fn from_pni(uuid: Uuid) -> Self {
Self {
uuid,
identity: ServiceIdType::PhoneNumberIdentity,
Expand Down Expand Up @@ -106,9 +116,9 @@ impl TryFrom<&ProtocolAddress> for ServiceAddress {
fn try_from(addr: &ProtocolAddress) -> Result<Self, Self::Error> {
let value = addr.name();
if let Some(pni) = value.strip_prefix("PNI:") {
Ok(ServiceAddress::new_pni(Uuid::parse_str(pni)?))
Ok(ServiceAddress::from_pni(Uuid::parse_str(pni)?))
} else {
Ok(ServiceAddress::new_aci(Uuid::parse_str(value)?))
Ok(ServiceAddress::from_aci(Uuid::parse_str(value)?))
}
.map_err(|e| {
tracing::error!("Parsing ServiceAddress from {:?}", addr);
Expand All @@ -122,9 +132,9 @@ impl TryFrom<&str> for ServiceAddress {

fn try_from(value: &str) -> Result<Self, Self::Error> {
if let Some(pni) = value.strip_prefix("PNI:") {
Ok(ServiceAddress::new_pni(Uuid::parse_str(pni)?))
Ok(ServiceAddress::from_pni(Uuid::parse_str(pni)?))
} else {
Ok(ServiceAddress::new_aci(Uuid::parse_str(value)?))
Ok(ServiceAddress::from_aci(Uuid::parse_str(value)?))
}
.map_err(|e| {
tracing::error!("Parsing ServiceAddress from '{}'", value);
Expand All @@ -138,9 +148,9 @@ impl TryFrom<&[u8]> for ServiceAddress {

fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
if let Some(pni) = value.strip_prefix(b"PNI:") {
Ok(ServiceAddress::new_pni(Uuid::from_slice(pni)?))
Ok(ServiceAddress::from_pni(Uuid::from_slice(pni)?))
} else {
Ok(ServiceAddress::new_aci(Uuid::from_slice(value)?))
Ok(ServiceAddress::from_aci(Uuid::from_slice(value)?))
}
.map_err(|e| {
tracing::error!("Parsing ServiceAddress from {:?}", value);
Expand Down

0 comments on commit e69ace5

Please sign in to comment.