diff --git a/.zed/settings.json b/.zed/settings.json new file mode 100644 index 0000000..4dcfc90 --- /dev/null +++ b/.zed/settings.json @@ -0,0 +1,15 @@ +// Folder-specific settings +// +// For a full list of overridable settings, and general information on folder-specific settings, +// see the documentation: https://zed.dev/docs/configuring-zed#settings-files +{ + "lsp": { + "rust-analyzer": { + "initialization_options": { + "rust": { + "analyzerTargetDir": true + } + } + } + } +} diff --git a/Cargo.lock b/Cargo.lock index 156025a..dc788c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anstream" version = "0.6.20" @@ -52,6 +61,39 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "base-x" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" + +[[package]] +name = "castaway" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dec551ab6e7578819132c713a93c022a05d60159dc86e7a7050223577484c55a" +dependencies = [ + "rustversion", +] + +[[package]] +name = "cfg-if" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" + +[[package]] +name = "cid" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3147d8272e8fa0ccd29ce51194dd98f79ddfb8191ba9e3409884e751798acf3a" +dependencies = [ + "core2", + "multibase", + "multihash", + "unsigned-varint", +] + [[package]] name = "clap" version = "4.5.48" @@ -98,6 +140,55 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "compact_str" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb1325a1cece981e8a296ab8f0f9b63ae357bd0784a9faaf548cc7b480707a" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "static_assertions", +] + +[[package]] +name = "core2" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" +dependencies = [ + "memchr", +] + +[[package]] +name = "data-encoding" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" + +[[package]] +name = "data-encoding-macro" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47ce6c96ea0102f01122a185683611bd5ac8d99e62bc59dd12e6bda344ee673d" +dependencies = [ + "data-encoding", + "data-encoding-macro-internal", +] + +[[package]] +name = "data-encoding-macro-internal" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d162beedaa69905488a8da94f5ac3edb4dd4788b732fadb7bd120b2625c1976" +dependencies = [ + "data-encoding", + "syn", +] + [[package]] name = "heck" version = "0.5.0" @@ -110,6 +201,12 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + [[package]] name = "jacquard" version = "0.1.0" @@ -117,6 +214,45 @@ dependencies = [ "clap", ] +[[package]] +name = "jacquard-common" +version = "0.1.0" +dependencies = [ + "cid", + "compact_str", + "multibase", + "multihash", + "regex", + "serde", +] + +[[package]] +name = "memchr" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" + +[[package]] +name = "multibase" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b3539ec3c1f04ac9748a260728e855f261b4977f5c3406612c884564f329404" +dependencies = [ + "base-x", + "data-encoding", + "data-encoding-macro", +] + +[[package]] +name = "multihash" +version = "0.19.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b430e7953c29dd6a09afc29ff0bb69c6e306329ee6794700aee27b76a1aea8d" +dependencies = [ + "core2", + "unsigned-varint", +] + [[package]] name = "once_cell_polyfill" version = "1.70.1" @@ -141,6 +277,83 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b5288124840bee7b386bc413c487869b360b2b4ec421ea56425128692f2a82c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "833eb9ce86d40ef33cb1306d8accf7bc8ec2bfea4355cbdebb3df68b40925cad" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.227" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80ece43fc6fbed4eb5392ab50c07334d3e577cbf40997ee896fe7af40bba4245" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.227" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a576275b607a2c86ea29e410193df32bc680303c82f31e275bbfcafe8b33be5" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.227" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e694923b8824cf0e9b382adf0f60d4e05f348f357b38833a3fa5ed7c2ede04" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.11.1" @@ -164,6 +377,12 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +[[package]] +name = "unsigned-varint" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" + [[package]] name = "utf8parse" version = "0.2.2" diff --git a/Cargo.toml b/Cargo.toml index 9b44f47..dcda9a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,10 +4,12 @@ members = ["crates/*"] [workspace.package] -authors = ["Orual "] edition = "2024" -description = "A simple Rust project using Nix" version = "0.1.0" +authors = ["Orual "] + +description = "A simple Rust project using Nix" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/jacquard-common/Cargo.toml b/crates/jacquard-common/Cargo.toml new file mode 100644 index 0000000..ccc81a5 --- /dev/null +++ b/crates/jacquard-common/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "jacquard-common" +edition.workspace = true +version.workspace = true +authors.workspace = true +description.workspace = true + +[dependencies] +cid = "0.11.1" +compact_str = "0.9.0" +multibase = "0.9.1" +multihash = "0.19.3" +regex = "1.11.3" +serde = { version = "1.0.227", features = ["derive"] } diff --git a/crates/jacquard-common/src/aturi.rs b/crates/jacquard-common/src/aturi.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/jacquard-common/src/blob.rs b/crates/jacquard-common/src/blob.rs new file mode 100644 index 0000000..8896d3c --- /dev/null +++ b/crates/jacquard-common/src/blob.rs @@ -0,0 +1,5 @@ +use crate::CowStr; + +/// Wrapper for file type +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +pub struct MimeType<'m>(pub CowStr<'m>); diff --git a/crates/jacquard-common/src/cid.rs b/crates/jacquard-common/src/cid.rs new file mode 100644 index 0000000..34ad03b --- /dev/null +++ b/crates/jacquard-common/src/cid.rs @@ -0,0 +1,20 @@ +use serde::{Deserialize, Serialize}; +use std::str:: + +pub use cid::Cid as IpldCid; + +/// raw +pub const ATP_CID_CODEC: u64 = 0x55; + +/// SHA-256 +pub const ATP_CID_HASH: u64 = 0x12; + +/// base 32 +pub const ATP_CID_BASE: multibase::Base = multibase::Base::Base32; + +#[derive(Serialize, Deserialize, Debug, Clone)] +#[serde(untagged)] +pub enum Cid { + Cid(IpldCid), + CidStr(CowStr<'static>), +} diff --git a/crates/jacquard-common/src/cowstr.rs b/crates/jacquard-common/src/cowstr.rs new file mode 100644 index 0000000..14d416b --- /dev/null +++ b/crates/jacquard-common/src/cowstr.rs @@ -0,0 +1,285 @@ +use std::{ + borrow::Cow, + fmt, + hash::{Hash, Hasher}, + ops::Deref, +}; + +use compact_str::CompactString; + +use crate::IntoStatic; + +/// Shamelessly copied from https://github.com/bearcove/merde +/// A copy-on-write string type that uses [`CompactString`] for +/// the "owned" variant. +/// +/// The standard [`Cow`] type cannot be used, since +/// `::Owned` is `String`, and not `CompactString`. +#[derive(Clone)] +pub enum CowStr<'s> { + Borrowed(&'s str), + Owned(CompactString), +} + +impl CowStr<'static> { + /// Create a new `CowStr` by copying from a `&str` — this might allocate + /// if the `compact_str` feature is disabled, or if the string is longer + /// than `MAX_INLINE_SIZE`. + pub fn copy_from_str(s: &str) -> Self { + Self::Owned(CompactString::from(s)) + } +} + +impl<'s> CowStr<'s> { + #[inline] + pub fn from_utf8(s: &'s [u8]) -> Result { + Ok(Self::Borrowed(std::str::from_utf8(s)?)) + } + + #[inline] + pub fn from_utf8_owned(s: Vec) -> Result { + Ok(Self::Owned(CompactString::from_utf8(s)?)) + } + + #[inline] + pub fn from_utf8_lossy(s: &'s [u8]) -> Self { + Self::Owned(CompactString::from_utf8_lossy(s)) + } + + /// # Safety + /// + /// This function is unsafe because it does not check that the bytes are valid UTF-8. + #[inline] + pub unsafe fn from_utf8_unchecked(s: &'s [u8]) -> Self { + unsafe { Self::Owned(CompactString::from_utf8_unchecked(s)) } + } +} + +impl AsRef for CowStr<'_> { + #[inline] + fn as_ref(&self) -> &str { + match self { + CowStr::Borrowed(s) => s, + CowStr::Owned(s) => s.as_str(), + } + } +} + +impl Deref for CowStr<'_> { + type Target = str; + + #[inline] + fn deref(&self) -> &Self::Target { + match self { + CowStr::Borrowed(s) => s, + CowStr::Owned(s) => s.as_str(), + } + } +} + +impl<'a> From> for CowStr<'a> { + #[inline] + fn from(s: Cow<'a, str>) -> Self { + match s { + Cow::Borrowed(s) => CowStr::Borrowed(s), + #[allow(clippy::useless_conversion)] + Cow::Owned(s) => CowStr::Owned(s.into()), + } + } +} + +impl<'s> From<&'s str> for CowStr<'s> { + #[inline] + fn from(s: &'s str) -> Self { + CowStr::Borrowed(s) + } +} + +impl From for CowStr<'_> { + #[inline] + fn from(s: String) -> Self { + #[allow(clippy::useless_conversion)] + CowStr::Owned(s.into()) + } +} + +impl From> for CowStr<'_> { + #[inline] + fn from(s: Box) -> Self { + CowStr::Owned(s.into()) + } +} + +impl<'s> From<&'s String> for CowStr<'s> { + #[inline] + fn from(s: &'s String) -> Self { + CowStr::Borrowed(s.as_str()) + } +} + +impl From> for String { + #[inline] + fn from(s: CowStr<'_>) -> Self { + match s { + CowStr::Borrowed(s) => s.into(), + #[allow(clippy::useless_conversion)] + CowStr::Owned(s) => s.into(), + } + } +} + +impl From> for Box { + #[inline] + fn from(s: CowStr<'_>) -> Self { + match s { + CowStr::Borrowed(s) => s.into(), + CowStr::Owned(s) => s.into(), + } + } +} + +impl<'a> PartialEq> for CowStr<'_> { + #[inline] + fn eq(&self, other: &CowStr<'a>) -> bool { + self.deref() == other.deref() + } +} + +impl PartialEq<&str> for CowStr<'_> { + #[inline] + fn eq(&self, other: &&str) -> bool { + self.deref() == *other + } +} + +impl PartialEq> for &str { + #[inline] + fn eq(&self, other: &CowStr<'_>) -> bool { + *self == other.deref() + } +} + +impl PartialEq for CowStr<'_> { + #[inline] + fn eq(&self, other: &String) -> bool { + self.deref() == other.as_str() + } +} + +impl PartialEq> for String { + #[inline] + fn eq(&self, other: &CowStr<'_>) -> bool { + self.as_str() == other.deref() + } +} + +impl Eq for CowStr<'_> {} + +impl Hash for CowStr<'_> { + #[inline] + fn hash(&self, state: &mut H) { + self.deref().hash(state) + } +} + +impl fmt::Debug for CowStr<'_> { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.deref().fmt(f) + } +} + +impl fmt::Display for CowStr<'_> { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.deref().fmt(f) + } +} + +impl IntoStatic for CowStr<'_> { + type Output = CowStr<'static>; + + #[inline] + fn into_static(self) -> Self::Output { + match self { + CowStr::Borrowed(s) => CowStr::Owned((*s).into()), + CowStr::Owned(s) => CowStr::Owned(s), + } + } +} + +use serde::{Deserialize, Serialize}; + +impl Serialize for CowStr<'_> { + #[inline] + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + serializer.serialize_str(self) + } +} + +impl<'de: 'a, 'a> Deserialize<'de> for CowStr<'a> { + #[inline] + fn deserialize(deserializer: D) -> Result, D::Error> + where + D: serde::Deserializer<'de>, + { + struct CowStrVisitor; + + impl<'de> serde::de::Visitor<'de> for CowStrVisitor { + type Value = CowStr<'de>; + + #[inline] + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + write!(formatter, "a string") + } + + #[inline] + fn visit_str(self, v: &str) -> Result + where + E: serde::de::Error, + { + Ok(CowStr::copy_from_str(v)) + } + + #[inline] + fn visit_borrowed_str(self, v: &'de str) -> Result + where + E: serde::de::Error, + { + Ok(CowStr::Borrowed(v)) + } + + #[inline] + fn visit_string(self, v: String) -> Result + where + E: serde::de::Error, + { + Ok(v.into()) + } + } + + deserializer.deserialize_str(CowStrVisitor) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_partialeq_with_str() { + let cow_str1 = CowStr::Borrowed("hello"); + let cow_str2 = CowStr::Borrowed("hello"); + let cow_str3 = CowStr::Borrowed("world"); + + assert_eq!(cow_str1, "hello"); + assert_eq!("hello", cow_str1); + assert_eq!(cow_str1, cow_str2); + assert_ne!(cow_str1, "world"); + assert_ne!("world", cow_str1); + assert_ne!(cow_str1, cow_str3); + } +} diff --git a/crates/jacquard-common/src/did.rs b/crates/jacquard-common/src/did.rs new file mode 100644 index 0000000..a887090 --- /dev/null +++ b/crates/jacquard-common/src/did.rs @@ -0,0 +1,3 @@ +use crate::CowStr; + +pub struct Did<'d>(CowStr<'d>); diff --git a/crates/jacquard-common/src/handle.rs b/crates/jacquard-common/src/handle.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/jacquard-common/src/into_static.rs b/crates/jacquard-common/src/into_static.rs new file mode 100644 index 0000000..0705666 --- /dev/null +++ b/crates/jacquard-common/src/into_static.rs @@ -0,0 +1,291 @@ +use std::borrow::Cow; +use std::collections::HashMap; +use std::collections::HashSet; +use std::collections::VecDeque; +use std::hash::BuildHasher; +use std::hash::Hash; +use std::sync::Arc; + +/// Shamelessly copied from https://github.com/bearcove/merde +/// Allow turning a value into an "owned" variant, which can then be +/// returned, moved, etc. +/// +/// This usually involves allocating buffers for `Cow<'a, str>`, etc. +pub trait IntoStatic: Sized { + /// The "owned" variant of the type. For `Cow<'a, str>`, this is `Cow<'static, str>`, for example. + type Output: 'static; + + /// Turns the value into an "owned" variant, which can then be returned, moved, etc. + /// + /// This allocates, for all but the most trivial types. + fn into_static(self) -> Self::Output; +} + +impl IntoStatic for Result +where + T: IntoStatic, + E: IntoStatic, +{ + type Output = Result; + + fn into_static(self) -> Self::Output { + match self { + Ok(v) => Ok(v.into_static()), + Err(e) => Err(e.into_static()), + } + } +} + +impl IntoStatic for Cow<'_, T> +where + T: ToOwned + ?Sized + 'static, +{ + type Output = Cow<'static, T>; + + #[inline(always)] + fn into_static(self) -> Self::Output { + match self { + Cow::Borrowed(b) => Cow::Owned(b.to_owned()), + Cow::Owned(o) => Cow::Owned(o), + } + } +} + +macro_rules! impl_into_static_passthru { + ($($ty:ty),+) => { + $( + impl IntoStatic for $ty { + type Output = $ty; + + #[inline(always)] + fn into_static(self) -> Self::Output { + self + } + } + )+ + }; +} + +impl_into_static_passthru!( + String, u128, u64, u32, u16, u8, i128, i64, i32, i16, i8, bool, char, usize, isize, f32, f64 +); + +impl IntoStatic for Box { + type Output = Box; + + fn into_static(self) -> Self::Output { + Box::new((*self).into_static()) + } +} + +impl IntoStatic for Option { + type Output = Option; + + fn into_static(self) -> Self::Output { + self.map(|v| v.into_static()) + } +} + +impl IntoStatic for Vec { + type Output = Vec; + + fn into_static(self) -> Self::Output { + self.into_iter().map(|v| v.into_static()).collect() + } +} + +impl IntoStatic for Arc { + type Output = Arc; + + fn into_static(self) -> Self::Output { + let t: T = (*self).clone(); + Arc::new(t.into_static()) + } +} + +impl IntoStatic for HashMap +where + S: BuildHasher + Default + 'static, + K: IntoStatic + Eq + Hash, + V: IntoStatic, + K::Output: Eq + Hash, +{ + type Output = HashMap; + + fn into_static(self) -> Self::Output { + self.into_iter() + .map(|(k, v)| (k.into_static(), v.into_static())) + .collect() + } +} + +impl IntoStatic for HashSet +where + T::Output: Eq + Hash, +{ + type Output = HashSet; + + fn into_static(self) -> Self::Output { + self.into_iter().map(|v| v.into_static()).collect() + } +} + +impl IntoStatic for VecDeque { + type Output = VecDeque; + + fn into_static(self) -> Self::Output { + self.into_iter().map(|v| v.into_static()).collect() + } +} + +impl IntoStatic for (T1,) { + type Output = (T1::Output,); + + fn into_static(self) -> Self::Output { + (self.0.into_static(),) + } +} + +impl IntoStatic for (T1, T2) { + type Output = (T1::Output, T2::Output); + + fn into_static(self) -> Self::Output { + (self.0.into_static(), self.1.into_static()) + } +} + +impl IntoStatic for (T1, T2, T3) { + type Output = (T1::Output, T2::Output, T3::Output); + + fn into_static(self) -> Self::Output { + ( + self.0.into_static(), + self.1.into_static(), + self.2.into_static(), + ) + } +} + +impl IntoStatic + for (T1, T2, T3, T4) +{ + type Output = (T1::Output, T2::Output, T3::Output, T4::Output); + + fn into_static(self) -> Self::Output { + ( + self.0.into_static(), + self.1.into_static(), + self.2.into_static(), + self.3.into_static(), + ) + } +} + +impl IntoStatic + for (T1, T2, T3, T4, T5) +{ + type Output = (T1::Output, T2::Output, T3::Output, T4::Output, T5::Output); + + fn into_static(self) -> Self::Output { + ( + self.0.into_static(), + self.1.into_static(), + self.2.into_static(), + self.3.into_static(), + self.4.into_static(), + ) + } +} + +impl + IntoStatic for (T1, T2, T3, T4, T5, T6) +{ + type Output = ( + T1::Output, + T2::Output, + T3::Output, + T4::Output, + T5::Output, + T6::Output, + ); + + fn into_static(self) -> Self::Output { + ( + self.0.into_static(), + self.1.into_static(), + self.2.into_static(), + self.3.into_static(), + self.4.into_static(), + self.5.into_static(), + ) + } +} + +impl< + T1: IntoStatic, + T2: IntoStatic, + T3: IntoStatic, + T4: IntoStatic, + T5: IntoStatic, + T6: IntoStatic, + T7: IntoStatic, +> IntoStatic for (T1, T2, T3, T4, T5, T6, T7) +{ + type Output = ( + T1::Output, + T2::Output, + T3::Output, + T4::Output, + T5::Output, + T6::Output, + T7::Output, + ); + + fn into_static(self) -> Self::Output { + ( + self.0.into_static(), + self.1.into_static(), + self.2.into_static(), + self.3.into_static(), + self.4.into_static(), + self.5.into_static(), + self.6.into_static(), + ) + } +} + +impl< + T1: IntoStatic, + T2: IntoStatic, + T3: IntoStatic, + T4: IntoStatic, + T5: IntoStatic, + T6: IntoStatic, + T7: IntoStatic, + T8: IntoStatic, +> IntoStatic for (T1, T2, T3, T4, T5, T6, T7, T8) +{ + type Output = ( + T1::Output, + T2::Output, + T3::Output, + T4::Output, + T5::Output, + T6::Output, + T7::Output, + T8::Output, + ); + + fn into_static(self) -> Self::Output { + ( + self.0.into_static(), + self.1.into_static(), + self.2.into_static(), + self.3.into_static(), + self.4.into_static(), + self.5.into_static(), + self.6.into_static(), + self.7.into_static(), + ) + } +} diff --git a/crates/jacquard-common/src/lib.rs b/crates/jacquard-common/src/lib.rs new file mode 100644 index 0000000..99c1b5a --- /dev/null +++ b/crates/jacquard-common/src/lib.rs @@ -0,0 +1,10 @@ +pub mod aturi; +pub mod cowstr; +pub mod did; +pub mod handle; +pub mod into_static; +pub mod link; +pub mod nsid; + +pub use cowstr::CowStr; +pub use into_static::IntoStatic; diff --git a/crates/jacquard-common/src/link.rs b/crates/jacquard-common/src/link.rs new file mode 100644 index 0000000..d3484ce --- /dev/null +++ b/crates/jacquard-common/src/link.rs @@ -0,0 +1 @@ +// strongref, blobref(s), cid links diff --git a/crates/jacquard-common/src/nsid.rs b/crates/jacquard-common/src/nsid.rs new file mode 100644 index 0000000..e69de29 diff --git a/crates/jacquard/Cargo.toml b/crates/jacquard/Cargo.toml index 6be30fc..1ad34ca 100644 --- a/crates/jacquard/Cargo.toml +++ b/crates/jacquard/Cargo.toml @@ -4,6 +4,7 @@ authors.workspace = true name = "jacquard" description = "A simple Rust project using Nix" version.workspace = true +edition.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/flake.lock b/flake.lock index dd3bb55..ef9f2e5 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "crane": { "locked": { - "lastModified": 1736566337, - "narHash": "sha256-SC0eDcZPqISVt6R0UfGPyQLrI0+BppjjtQ3wcSlk0oI=", + "lastModified": 1757183466, + "narHash": "sha256-kTdCCMuRE+/HNHES5JYsbRHmgtr+l9mOtf5dpcMppVc=", "owner": "ipetkov", "repo": "crane", - "rev": "9172acc1ee6c7e1cbafc3044ff850c568c75a5a3", + "rev": "d599ae4847e7f87603e7082d73ca673aa93c916d", "type": "github" }, "original": { @@ -37,11 +37,11 @@ ] }, "locked": { - "lastModified": 1725234343, - "narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=", + "lastModified": 1756770412, + "narHash": "sha256-+uWLQZccFHwqpGqr2Yt5VsW/PbeJVTn9Dk6SHWhNRPw=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "567b938d64d4b4112ee253b9274472dc3a346eb6", + "rev": "4524271976b625a4a605beefd893f270620fd751", "type": "github" }, "original": { @@ -53,11 +53,11 @@ "git-hooks": { "flake": false, "locked": { - "lastModified": 1734425854, - "narHash": "sha256-nzE5UbJ41aPEKf8R2ZFYtLkqPmF7EIUbNEdHMBLg0Ig=", + "lastModified": 1758108966, + "narHash": "sha256-ytw7ROXaWZ7OfwHrQ9xvjpUWeGVm86pwnEd1QhzawIo=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "0ddd26d0925f618c3a5d85a4fa5eb1e23a09491d", + "rev": "54df955a695a84cd47d4a43e08e1feaf90b1fd9b", "type": "github" }, "original": { @@ -68,11 +68,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1736693123, - "narHash": "sha256-9lIfXCaBPwUA7FnfDnoH4gxxdOvXG78k6UlUw0+ZDxc=", + "lastModified": 1758763312, + "narHash": "sha256-puBMviZhYlqOdUUgEmMVJpXqC/ToEqSvkyZ30qQ09xM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2fdec2c2e68b7b7845d1ea4e0894c63143e3261b", + "rev": "e57b3b16ad8758fd681511a078f35c416a8cc939", "type": "github" }, "original": { @@ -84,11 +84,11 @@ }, "process-compose-flake": { "locked": { - "lastModified": 1724606023, - "narHash": "sha256-rdGeNa/lCS8E1lXzPqgl+vZUUvnbEZT11Bqkx5jfYug=", + "lastModified": 1758658658, + "narHash": "sha256-y5GSCqlGe/uZzlocCPZcjc7Gj+mTq7m0P6xPGx88+No=", "owner": "Platonic-Systems", "repo": "process-compose-flake", - "rev": "f6ce9481df9aec739e4e06b67492401a5bb4f0b1", + "rev": "e968a94633788f5d9595d727f41c2baf0714be7b", "type": "github" }, "original": { @@ -117,11 +117,11 @@ "rust-overlay": "rust-overlay" }, "locked": { - "lastModified": 1736806612, - "narHash": "sha256-WioA+Vk7suDK+Ek77rDlbuxV6WqwFt30JsKHrmDCSiU=", + "lastModified": 1757862855, + "narHash": "sha256-XPqlAQkx8rvG89nw+SbU6TiGVYPWdYIklPljdAyjp7w=", "owner": "juspay", "repo": "rust-flake", - "rev": "b5f39885e2fcf137bfaf75decc077f9cca2bd984", + "rev": "fa28d6e30b5d13014f24354dc49e717733fbb995", "type": "github" }, "original": { @@ -138,11 +138,11 @@ ] }, "locked": { - "lastModified": 1736700680, - "narHash": "sha256-9gmWIb8xsycWHEYpd2SiVIAZnUULX6Y+IMMZBcDUCQU=", + "lastModified": 1757730403, + "narHash": "sha256-Jxl4OZRVsXs8JxEHUVQn3oPu6zcqFyGGKaFrlNgbzp0=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "5d1865c0da63b4c949f383d982b6b43519946e8f", + "rev": "3232f7f8bd07849fc6f4ae77fe695e0abb2eba2c", "type": "github" }, "original": { diff --git a/nix/modules/rust.nix b/nix/modules/rust.nix index 525ee02..e600bcc 100644 --- a/nix/modules/rust.nix +++ b/nix/modules/rust.nix @@ -46,6 +46,17 @@ }; }; }; + + "jacquard-common" = { + imports = [globalCrateConfig]; + autoWire = ["crate" "clippy"]; + path = ./../../crates/jacquard-common; + crane = { + args = { + buildInputs = commonBuildInputs; + }; + }; + }; }; }; packages.default = self'.packages.jacquard;