Skip to content

Commit

Permalink
initial work to rewrite the elements logic for hotreload
Browse files Browse the repository at this point in the history
  • Loading branch information
rambip committed Dec 9, 2024
1 parent 74192df commit 465b6a3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/manganis/manganis-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ pub use js::*;
mod asset;
pub use asset::*;

mod metadata;
pub use metadata::*;

pub mod linker;
32 changes: 32 additions & 0 deletions packages/manganis/manganis-core/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use const_serialize::{ConstStr, SerializeConst};
use std::path::PathBuf;

#[derive(
Debug,
PartialEq,
PartialOrd,
Clone,
Copy,
Hash,
SerializeConst,
serde::Serialize,
serde::Deserialize,
)]
pub struct Metadata {
key: ConstStr,
value: ConstStr,
keep_link_section: fn() -> u8,
}

impl Metadata {
#[doc(hidden)]
/// This should only be called from the macro
/// Create a new metadata
pub const fn new(key: &'static str, value: &'static str, keep_link_section: fn() -> u8) -> Self {
Self {
key: ConstStr::new(key),
value: ConstStr::new(value),
keep_link_section,
}
}
}
6 changes: 6 additions & 0 deletions packages/manganis/manganis/src/macro_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ pub const fn serialize_asset(asset: &BundledAsset) -> ConstVec<u8> {
serialize_const(asset, write)
}

/// Serialize metadata to a const buffer
pub const fn selialize_metadata(metadata: &BundledMetadata) -> ConstVec<u8> {
let write = ConstVec::new();
serialize_const(metadata, write)
}

/// Copy a slice into a constant sized buffer at compile time
pub const fn copy_bytes<const N: usize>(bytes: &[u8]) -> [u8; N] {
let mut out = [0; N];
Expand Down

0 comments on commit 465b6a3

Please sign in to comment.