-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rust package
embedded-std
with module string
Having our own std library with newtypes allows us to implement traits of `ufmt`.
- Loading branch information
Showing
5 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
# SPDX-FileCopyrightText: 2022 Google LLC | ||
# SPDX-FileCopyrightText: 2022-2024 Google LLC | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
|
||
[workspace] | ||
members = [ | ||
"bittide-sys", | ||
"embedded-std", | ||
] | ||
resolver = "2" |
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,30 @@ | ||
# SPDX-FileCopyrightText: 2024 Google LLC | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
|
||
[package] | ||
name = "embedded-std" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
authors = ["Google LLC"] | ||
resolver = "2" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
panic-handler = [] | ||
default = [] | ||
|
||
[dependencies] | ||
ufmt = "0.2.0" | ||
heapless = { version = "0.7", default-features = false} | ||
|
||
[dev-dependencies] | ||
proptest = "1.0" | ||
object = { version = "0.28", features = ["write"] } | ||
libc = "0.2" | ||
test-strategy = "0.2.0" | ||
rand = "0.8" | ||
lazy_static = "1.0" | ||
tempfile = "3" |
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,7 @@ | ||
// SPDX-FileCopyrightText: 2024 Google LLC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#![no_std] | ||
|
||
pub mod string; |
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,31 @@ | ||
// SPDX-FileCopyrightText: 2024 Google LLC | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use ufmt::{uDisplay, uWrite}; | ||
|
||
#[derive(Clone)] | ||
pub struct String<const SIZE: usize>(pub heapless::String<SIZE>); | ||
|
||
impl <const SIZE: usize> String<SIZE> { | ||
pub fn new() -> Self { | ||
String(heapless::String::new()) | ||
} | ||
} | ||
|
||
impl<const SIZE: usize> uDisplay for String<SIZE> { | ||
#[inline(always)] | ||
fn fmt<W>(&self, f: &mut ufmt::Formatter<'_, W>) -> Result<(), W::Error> | ||
where | ||
W: uWrite + ?Sized, | ||
{ | ||
f.write_str(&self.0.as_str()) | ||
} | ||
} | ||
|
||
impl <const SIZE: usize> ufmt::uWrite for String<SIZE> { | ||
fn write_str(&mut self, s: &str) -> Result<(), Self::Error> { | ||
self.0.push_str(s)?; | ||
Ok(()) | ||
} | ||
type Error = (); | ||
} |