mirror of
				https://github.com/rust-embedded/heapless.git
				synced 2025-11-04 06:56:48 +00:00 
			
		
		
		
	vec: remove code duplication due to VecView.
This commit is contained in:
		
							parent
							
								
									1f25e658ca
								
							
						
					
					
						commit
						e9f8bac7ec
					
				
							
								
								
									
										10
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/lib.rs
									
									
									
									
									
								
							@ -96,13 +96,6 @@ pub use indexmap::{
 | 
				
			|||||||
pub use indexset::{FnvIndexSet, IndexSet, Iter as IndexSetIter};
 | 
					pub use indexset::{FnvIndexSet, IndexSet, Iter as IndexSetIter};
 | 
				
			||||||
pub use linear_map::LinearMap;
 | 
					pub use linear_map::LinearMap;
 | 
				
			||||||
pub use string::String;
 | 
					pub use string::String;
 | 
				
			||||||
 | 
					 | 
				
			||||||
// Workaround https://github.com/rust-lang/rust/issues/119015. This is required so that the methods on `VecView` and `Vec` are properly documented.
 | 
					 | 
				
			||||||
// cfg(doc) prevents `VecInner` being part of the public API.
 | 
					 | 
				
			||||||
// doc(hidden) prevents the `pub use vec::VecInner` from being visible in the documentation.
 | 
					 | 
				
			||||||
#[cfg(doc)]
 | 
					 | 
				
			||||||
#[doc(hidden)]
 | 
					 | 
				
			||||||
pub use vec::VecInner as _;
 | 
					 | 
				
			||||||
pub use vec::{Vec, VecView};
 | 
					pub use vec::{Vec, VecView};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[macro_use]
 | 
					#[macro_use]
 | 
				
			||||||
@ -114,8 +107,9 @@ mod histbuf;
 | 
				
			|||||||
mod indexmap;
 | 
					mod indexmap;
 | 
				
			||||||
mod indexset;
 | 
					mod indexset;
 | 
				
			||||||
mod linear_map;
 | 
					mod linear_map;
 | 
				
			||||||
 | 
					pub mod storage;
 | 
				
			||||||
pub mod string;
 | 
					pub mod string;
 | 
				
			||||||
mod vec;
 | 
					pub mod vec;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(feature = "serde")]
 | 
					#[cfg(feature = "serde")]
 | 
				
			||||||
mod de;
 | 
					mod de;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										35
									
								
								src/storage.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/storage.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,35 @@
 | 
				
			|||||||
 | 
					//! `Storage` trait defining how data is stored in a container.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use core::borrow::{Borrow, BorrowMut};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub(crate) trait SealedStorage {
 | 
				
			||||||
 | 
					    type Buffer<T>: ?Sized + Borrow<[T]> + BorrowMut<[T]>;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Trait defining how data for a container is stored.
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// There's two implementations available:
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// - [`OwnedStorage`]: stores the data in an array `[T; N]` whose size is known at compile time.
 | 
				
			||||||
 | 
					/// - [`ViewStorage`]: stores the data in an unsized `[T]`.
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// This allows containers to be generic over either sized or unsized storage.
 | 
				
			||||||
 | 
					///
 | 
				
			||||||
 | 
					/// This trait is sealed, so you cannot implement it for your own types. You can only use
 | 
				
			||||||
 | 
					/// the implementations provided by this crate.
 | 
				
			||||||
 | 
					#[allow(private_bounds)]
 | 
				
			||||||
 | 
					pub trait Storage: SealedStorage {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Implementation of [`Storage`] that stores the data in an array `[T; N]` whose size is known at compile time.
 | 
				
			||||||
 | 
					pub enum OwnedStorage<const N: usize> {}
 | 
				
			||||||
 | 
					impl<const N: usize> Storage for OwnedStorage<N> {}
 | 
				
			||||||
 | 
					impl<const N: usize> SealedStorage for OwnedStorage<N> {
 | 
				
			||||||
 | 
					    type Buffer<T> = [T; N];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Implementation of [`Storage`] that stores the data in an unsized `[T]`.
 | 
				
			||||||
 | 
					pub enum ViewStorage {}
 | 
				
			||||||
 | 
					impl Storage for ViewStorage {}
 | 
				
			||||||
 | 
					impl SealedStorage for ViewStorage {
 | 
				
			||||||
 | 
					    type Buffer<T> = [T];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										1532
									
								
								src/vec.rs
									
									
									
									
									
								
							
							
						
						
									
										1532
									
								
								src/vec.rs
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user