-
-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ pub mod attr; | |
mod case; | ||
mod check; | ||
mod ctxt; | ||
mod name; | ||
mod receiver; | ||
mod respan; | ||
mod symbol; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use crate::internals::attr::{Attr, VecAttr}; | ||
use std::collections::BTreeSet; | ||
|
||
pub struct MultiName { | ||
pub(crate) serialize: String, | ||
pub(crate) serialize_renamed: bool, | ||
pub(crate) deserialize: String, | ||
pub(crate) deserialize_renamed: bool, | ||
pub(crate) deserialize_aliases: BTreeSet<String>, | ||
} | ||
|
||
impl MultiName { | ||
pub(crate) fn from_attrs( | ||
source_name: String, | ||
ser_name: Attr<String>, | ||
de_name: Attr<String>, | ||
de_aliases: Option<VecAttr<String>>, | ||
) -> Self { | ||
let mut alias_set = BTreeSet::new(); | ||
if let Some(de_aliases) = de_aliases { | ||
for alias_name in de_aliases.get() { | ||
alias_set.insert(alias_name); | ||
} | ||
} | ||
|
||
let ser_name = ser_name.get(); | ||
let ser_renamed = ser_name.is_some(); | ||
let de_name = de_name.get(); | ||
let de_renamed = de_name.is_some(); | ||
MultiName { | ||
serialize: ser_name.unwrap_or_else(|| source_name.clone()), | ||
serialize_renamed: ser_renamed, | ||
deserialize: de_name.unwrap_or(source_name), | ||
deserialize_renamed: de_renamed, | ||
deserialize_aliases: alias_set, | ||
} | ||
} | ||
|
||
/// Return the container name for the container when serializing. | ||
pub fn serialize_name(&self) -> &str { | ||
&self.serialize | ||
} | ||
|
||
/// Return the container name for the container when deserializing. | ||
pub fn deserialize_name(&self) -> &str { | ||
&self.deserialize | ||
} | ||
|
||
pub(crate) fn deserialize_aliases(&self) -> &BTreeSet<String> { | ||
&self.deserialize_aliases | ||
} | ||
} |