lkml.org 
[lkml]   [2022]   [Sep]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v10 08/27] rust: adapt `alloc` crate to the kernel
On Tue, Sep 27, 2022 at 03:14:39PM +0200, Miguel Ojeda wrote:
[...]
> + /// Tries to append an element to the back of a collection.
> + ///
> + /// # Examples
> + ///
> + /// ```
> + /// let mut vec = vec![1, 2];
> + /// vec.try_push(3).unwrap();
> + /// assert_eq!(vec, [1, 2, 3]);
> + /// ```
> + #[inline]
> + #[stable(feature = "kernel", since = "1.0.0")]
> + pub fn try_push(&mut self, value: T) -> Result<(), TryReserveError> {
> + if self.len == self.buf.capacity() {
> + self.buf.try_reserve_for_push(self.len)?;
> + }
> + unsafe {
> + let end = self.as_mut_ptr().add(self.len);
> + ptr::write(end, value);
> + self.len += 1;
> + }
> + Ok(())
> + }
[...]

Not being able to pass GFP flags here kinda limits the scope of Rust in
kernel. I think that it must be supported in the final version that gets
in.

\
 
 \ /
  Last update: 2022-09-27 15:52    [W:0.523 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site