use std::mem;
use std::mem::MaybeUninit;
use crate::well_known_types;
pub(crate) fn maybe_uninit_write_slice<'a, T>(
this: &'a mut [MaybeUninit<T>],
src: &[T],
) -> &'a mut [T]
where
T: Copy,
{
let uninit_src: &[MaybeUninit<T>] = unsafe { mem::transmute(src) };
this.copy_from_slice(uninit_src);
unsafe { &mut *(this as *mut [MaybeUninit<T>] as *mut [T]) }
}
#[inline]
pub(crate) unsafe fn maybe_ununit_array_assume_init<T, const N: usize>(
array: [MaybeUninit<T>; N],
) -> [T; N] {
(&array as *const _ as *const [T; N]).read()
}
impl From<well_known_types::wrappers::BoolValue> for bool {
fn from(inner: well_known_types::wrappers::BoolValue) -> Self {
inner.value
}
}
impl From<bool> for well_known_types::wrappers::BoolValue {
fn from(inner: bool) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::BytesValue> for Vec<u8> {
fn from(inner: well_known_types::wrappers::BytesValue) -> Self {
inner.value
}
}
impl From<Vec<u8>> for well_known_types::wrappers::BytesValue {
fn from(inner: Vec<u8>) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::DoubleValue> for f64 {
fn from(inner: well_known_types::wrappers::DoubleValue) -> Self {
inner.value
}
}
impl From<f64> for well_known_types::wrappers::DoubleValue {
fn from(inner: f64) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::FloatValue> for f32 {
fn from(inner: well_known_types::wrappers::FloatValue) -> Self {
inner.value
}
}
impl From<f32> for well_known_types::wrappers::FloatValue {
fn from(inner: f32) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::Int32Value> for i32 {
fn from(inner: well_known_types::wrappers::Int32Value) -> Self {
inner.value
}
}
impl From<i32> for well_known_types::wrappers::Int32Value {
fn from(inner: i32) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::Int64Value> for i64 {
fn from(inner: well_known_types::wrappers::Int64Value) -> Self {
inner.value
}
}
impl From<i64> for well_known_types::wrappers::Int64Value {
fn from(inner: i64) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::UInt32Value> for u32 {
fn from(inner: well_known_types::wrappers::UInt32Value) -> Self {
inner.value
}
}
impl From<u32> for well_known_types::wrappers::UInt32Value {
fn from(inner: u32) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::wrappers::UInt64Value> for u64 {
fn from(inner: well_known_types::wrappers::UInt64Value) -> Self {
inner.value
}
}
impl From<u64> for well_known_types::wrappers::UInt64Value {
fn from(inner: u64) -> Self {
let mut value = Self::new();
value.value = inner;
value
}
}
impl From<well_known_types::empty::Empty> for () {
fn from(_inner: well_known_types::empty::Empty) -> Self {}
}
impl From<()> for well_known_types::empty::Empty {
fn from(_inner: ()) -> Self {
Self::new()
}
}