-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
146 additions
and
5 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
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
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
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,39 @@ | ||
// TODO: Restrict this to only non-JS/TS languages. | ||
|
||
use std::{ | ||
borrow::{Borrow, Cow}, | ||
collections::HashMap, | ||
}; | ||
|
||
use serde::Serialize; | ||
|
||
/// Define a set of statics which can be included in the exporter | ||
#[derive(Debug, Default, Clone, PartialEq, Eq)] | ||
pub struct StaticCollection { | ||
pub(crate) statics: HashMap<Cow<'static, str>, serde_json::Value>, | ||
} | ||
|
||
impl StaticCollection { | ||
/// Join another type collection into this one. | ||
pub fn extend(&mut self, collection: impl Borrow<StaticCollection>) -> &mut Self { | ||
self.statics.extend( | ||
collection | ||
.borrow() | ||
.statics | ||
.iter() | ||
.map(|(k, v)| (k.clone(), v.clone())), | ||
); | ||
self | ||
} | ||
|
||
/// Register a static with the collection. | ||
pub fn register<T: Serialize>( | ||
&mut self, | ||
name: impl Into<Cow<'static, str>>, | ||
value: T, | ||
) -> &mut Self { | ||
self.statics | ||
.insert(name.into(), serde_json::to_value(&value).unwrap()); | ||
self | ||
} | ||
} |
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