dicom_core/dictionary/
uid.rsuse std::str::FromStr;
pub trait UidDictionary {
type Entry: UidDictionaryEntry;
fn by_keyword(&self, keyword: &str) -> Option<&Self::Entry>;
fn by_uid(&self, uid: &str) -> Option<&Self::Entry>;
}
pub trait UidDictionaryEntry {
fn uid(&self) -> &str;
fn name(&self) -> &str;
fn alias(&self) -> &str;
fn is_retired(&self) -> bool;
}
#[derive(Debug, PartialEq, Clone)]
pub struct UidDictionaryEntryRef<'a> {
pub uid: &'a str,
pub name: &'a str,
pub alias: &'a str,
pub r#type: UidType,
pub retired: bool,
}
impl<'a> UidDictionaryEntryRef<'a> {
pub const fn new(
uid: &'a str,
name: &'a str,
alias: &'a str,
r#type: UidType,
retired: bool,
) -> Self {
UidDictionaryEntryRef {
uid,
name,
alias,
r#type,
retired,
}
}
}
impl UidDictionaryEntry for UidDictionaryEntryRef<'_> {
fn uid(&self) -> &str {
self.uid
}
fn name(&self) -> &str {
self.name
}
fn alias(&self) -> &str {
self.alias
}
fn is_retired(&self) -> bool {
self.retired
}
}
#[non_exhaustive]
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
pub enum UidType {
SopClass,
MetaSopClass,
TransferSyntax,
WellKnownSopInstance,
DicomUidsAsCodingScheme,
CodingScheme,
ApplicationContextName,
ServiceClass,
ApplicationHostingModel,
MappingResource,
LdapOid,
SynchronizationFrameOfReference,
}
impl FromStr for UidType {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.trim() {
"SOP Class" => Ok(UidType::SopClass),
"Meta SOP Class" => Ok(UidType::MetaSopClass),
"Transfer Syntax" => Ok(UidType::TransferSyntax),
"Well-known SOP Instance" => Ok(UidType::WellKnownSopInstance),
"DICOM UIDs as a Coding Scheme" => Ok(UidType::DicomUidsAsCodingScheme),
"Coding Scheme" => Ok(UidType::CodingScheme),
"Application Context Name" => Ok(UidType::ApplicationContextName),
"Service Class" => Ok(UidType::ServiceClass),
"Application Hosting Model" => Ok(UidType::ApplicationHostingModel),
"Mapping Resource" => Ok(UidType::MappingResource),
"LDAP OID" => Ok(UidType::LdapOid),
"Synchronization Frame of Reference" => Ok(UidType::SynchronizationFrameOfReference),
_ => Err(()),
}
}
}
impl std::fmt::Display for UidType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
UidType::SopClass => "SOP Class",
UidType::MetaSopClass => "Meta SOP Class",
UidType::TransferSyntax => "Transfer Syntax",
UidType::WellKnownSopInstance => "Well-known SOP Instance",
UidType::DicomUidsAsCodingScheme => "DICOM UIDs as a Coding Scheme",
UidType::CodingScheme => "Coding Scheme",
UidType::ApplicationContextName => "Application Context Name",
UidType::ServiceClass => "Service Class",
UidType::ApplicationHostingModel => "Application Hosting Model",
UidType::MappingResource => "Mapping Resource",
UidType::LdapOid => "LDAP OID",
UidType::SynchronizationFrameOfReference => "Synchronization Frame of Reference",
};
f.write_str(str)
}
}