pub fn try_from_slice(slice: &[T]) -> Result<&Self, BitSpanError<T>> {
		let elts = slice.len();
		if elts >= Self::MAX_ELTS {
			elts.saturating_mul(mem::bits_of::<T::Mem>())
				.pipe(BitSpanError::TooLong)
				.pipe(Err)
		}
		else {
			Ok(unsafe { Self::from_slice_unchecked(slice) })
		}
	}
/// Attempts to construct a shared `&BitSlice` reference over a slice of
/// elements.
///
/// The [`BitView`], implemented on all `[T]` slices, provides a
/// [`.try_view_bits::<O>()`] method which delegates to this function and
/// may be more convenient for you to write.
///
/// This is *very hard*, if not impossible, to cause to fail. Rust will not
/// create excessive arrays on 64-bit architectures.
///
/// ## Parameters
///
/// - `slice`: A shared reference to a slice of memory elements.
///
/// ## Returns
///
/// A shared `&BitSlice` over `slice`. If `slice` is longer than can be
/// encoded into a `&BitSlice` (see [`MAX_ELTS`]), this will fail and return
/// the original `slice` as an error.
///
/// ## Examples
///
/// ```rust
/// use bitvec::prelude::*;
///
/// let data = [0u8, 1];
/// let bits = BitSlice::<_, Msb0>::try_from_slice(&data).unwrap();
/// assert!(bits[15]);
///
/// let bits = data.try_view_bits::<Msb0>().unwrap();
/// ```
///
/// [`BitView`]: crate::view::BitView
/// [`MAX_ELTS`]: Self::MAX_ELTS
/// [`.try_view_bits::<O>()`]: crate::view::BitView::try_view_bits
Attempts to construct a shared `&BitSlice` reference over a slice of
elements.



This is *very hard*, if not impossible, to cause to fail. Rust will not
create excessive arrays on 64-bit architectures.
Attempts to construct a shared ` &BitSlice ` reference over a slice of elements . This is * very hard * if not impossible to cause to fail . Rust will not create excessive arrays on 64 - bit architectures .
pub fn try_from_slice(slice: &[T]) -> Result<&Self, BitSpanError<T>> {
		let elts = slice.len();
		if elts >= Self::MAX_ELTS {
			elts.saturating_mul(mem::bits_of::<T::Mem>())
				.pipe(BitSpanError::TooLong)
				.pipe(Err)
		}
		else {
			Ok(unsafe { Self::from_slice_unchecked(slice) })
		}
	}
pub fn try_from_slice ( slice : & [ T ] ) -> Result < & Self , BitSpanError < T > > { let elts = slice . len ( ) ; if elts >= Self :: MAX_ELTS { elts . saturating_mul ( mem :: bits_of :: < T :: Mem > ( ) ) . pipe ( BitSpanError :: TooLong ) . pipe ( Err ) } else { Ok ( unsafe { Self :: from_slice_unchecked ( slice ) } ) } }
Attempts to construct a shared `&BitSlice` reference over a slice of
elements.
Attempts to construct a shared ` &BitSlice ` reference over a slice of elements .
slice
&[T]
A shared `&BitSlice` over `slice`. If `slice` is longer than can be
encoded into a `&BitSlice` , this will fail and return
the original `slice` as an error.
A shared ` &BitSlice ` over ` slice ` . If ` slice ` is longer than can be encoded into a ` &BitSlice ` this will fail and return the original ` slice ` as an error .
slice
&[T]
A shared reference to a slice of memory elements.
A shared reference to a slice of memory elements .
examples
```rust
use bitvec::prelude::*.



let bits = data.try_view_bits::().unwrap();
```


` ` ` rust use bitvec :: prelude :: * . let bits = data . try_view_bits :: () . unwrap () ; ` ` `