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

Implements TryFrom for Deque from array #524

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

hicklin
Copy link
Contributor

@hicklin hicklin commented Dec 16, 2024

Fixes #522.

Ideally, this PR is updated after PR #521 is merged to simplify the tests.

This PR implements the TryFrom trait for creating a Deque from a slice.

Note the use of unsafe for copying all bytes from the slice to the Deque buffer after ensuring that the Deque buffer has enough space.

Also note the use of ManuallyDrop to ensure that any heap memory referred to by the element contents is not dropped at the end of this method since the elements in the Deque buffer will be pointing to it.

@hicklin hicklin changed the title Implemented TyrFrom for Deque from slice. Implements TyrFrom for Deque from array. Jan 9, 2025
@hicklin hicklin changed the title Implements TyrFrom for Deque from array. Implements TyrFrom for Deque from array Jan 9, 2025
Copy link
Member

@newAM newAM left a comment

Choose a reason for hiding this comment

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

I wont be able to properly review this for a bit, wanted to highlight a couple typos until then.

@hicklin hicklin requested a review from newAM January 14, 2025 11:51
@hicklin hicklin force-pushed the impl_try_from_for_deque branch from aa6f7a2 to e922e5a Compare February 18, 2025 14:19
Copy link
Member

@newAM newAM left a comment

Choose a reason for hiding this comment

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

Sorry for the slow review, can merge after these small changes!

@newAM newAM changed the title Implements TyrFrom for Deque from array Implements TryFrom for Deque from array Mar 9, 2025
@hicklin hicklin force-pushed the impl_try_from_for_deque branch from 9c6db76 to 8907839 Compare March 20, 2025 13:21
@hicklin hicklin requested a review from newAM March 20, 2025 13:59
@@ -2,3 +2,4 @@
.#*
Cargo.lock
target/
.idea
Copy link
Member

Choose a reason for hiding this comment

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

Remove this.

/// ```
/// use heapless::Deque;
///
/// let deq1 = Deque::<u8, 4>::try_from([1, 2, 3, 4]).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Might make more sense to use different NS/ND in the example.

///
/// assert_eq!(deq1, deq2);
/// ```
type Error = ();
Copy link
Member

Choose a reason for hiding this comment

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

Should use CapacityError.

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.

Implement the From or TryFrom traits for Deque
4 participants