Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add embedded std #467

Closed
wants to merge 1 commit into from
Closed

Add embedded std #467

wants to merge 1 commit into from

Conversation

lmbollen
Copy link
Contributor

Rust's orphan rules prevent us from deriving traits like uDisplay, uDebug and uWrite from the ufmt package, effectively preventing us from formatting strings with existing types.

Therefore I propose to create an std like package that contains newtype wrappers for commonly used datatypes.
A first example is string.rs that uses String from heapless.

@@ -0,0 +1,30 @@
# SPDX-FileCopyrightText: 2022 Google LLC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a just written file, not a two year old file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, should have looke more carefully at the copyrights :)

@hydrolarus
Copy link
Contributor

hydrolarus commented Feb 26, 2024

What types are the ones that cause you trouble? Because heapless has a feature flag ufmt that adds formatting to the types

https://github.com/rust-embedded/heapless/blob/f3aa0df15a5320fcc0849d0e2562d6e281cc0c8c/Cargo.toml#L33-L34

I see that we are using a different feature flag, ufmt-impl, I guess they changed the name in a newer version. So maybe we should update that too? We are using 0.7.x but there's a version 0.8.0 out.

@lmbollen
Copy link
Contributor Author

What types are the ones that cause you trouble? Because heapless has a feature flag ufmt that adds formatting to the types

https://github.com/rust-embedded/heapless/blob/f3aa0df15a5320fcc0849d0e2562d6e281cc0c8c/Cargo.toml#L33-L34

I see that we are using a different feature flag, ufmt-impl, I guess they changed the name in a newer version. So maybe we should update that too? We are using 0.7.x but there's a version 0.8.0 out.

Oh nice! I'll take a look at those features and see if they cover my use cases :)
For now I'll turn this into a draft and I'll close it if it turns out unnecessary.

@lmbollen lmbollen marked this pull request as draft February 27, 2024 08:07
@lmbollen
Copy link
Contributor Author

It turns out the ufmt feature of heapless does not implement uDisplay for their String, which is a desirable feature to me.

I did make a pull request for it on their repository

For now I propose we do continue adding this package. If we don't find any value for it besides this trait I'd like to remove it if heapless supports the feature in the future.

Having our own std library with newtypes allows us to implement
traits of `ufmt`.
@lmbollen
Copy link
Contributor Author

Lara pointed out we can just use the as_str() to print Strings.

@lmbollen lmbollen closed this Feb 28, 2024
@martijnbastiaan martijnbastiaan deleted the add-embedded-std branch February 28, 2024 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants