1use crate::crates::CrateId;
4use crate::error::{err, Result};
5use crate::load::FromRecord;
6use crate::teams::TeamId;
7use crate::users::UserId;
8use chrono::{DateTime, Utc};
9use csv::StringRecord;
10use serde_derive::Deserialize;
11
12#[derive(#[automatically_derived]
impl ::core::marker::Copy for OwnerId { }Copy, #[automatically_derived]
impl ::core::clone::Clone for OwnerId {
#[inline]
fn clone(&self) -> OwnerId {
let _: ::core::clone::AssertParamIsClone<UserId>;
let _: ::core::clone::AssertParamIsClone<TeamId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::cmp::Ord for OwnerId {
#[inline]
fn cmp(&self, other: &OwnerId) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match ::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr) {
::core::cmp::Ordering::Equal =>
match (self, other) {
(OwnerId::User(__self_0), OwnerId::User(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
(OwnerId::Team(__self_0), OwnerId::Team(__arg1_0)) =>
::core::cmp::Ord::cmp(__self_0, __arg1_0),
_ => unsafe { ::core::intrinsics::unreachable() }
},
cmp => cmp,
}
}
}Ord, #[automatically_derived]
impl ::core::cmp::PartialOrd for OwnerId {
#[inline]
fn partial_cmp(&self, other: &OwnerId)
-> ::core::option::Option<::core::cmp::Ordering> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
match (self, other) {
(OwnerId::User(__self_0), OwnerId::User(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
(OwnerId::Team(__self_0), OwnerId::Team(__arg1_0)) =>
::core::cmp::PartialOrd::partial_cmp(__self_0, __arg1_0),
_ =>
::core::cmp::PartialOrd::partial_cmp(&__self_discr,
&__arg1_discr),
}
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Eq for OwnerId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<UserId>;
let _: ::core::cmp::AssertParamIsEq<TeamId>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for OwnerId {
#[inline]
fn eq(&self, other: &OwnerId) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(OwnerId::User(__self_0), OwnerId::User(__arg1_0)) =>
__self_0 == __arg1_0,
(OwnerId::Team(__self_0), OwnerId::Team(__arg1_0)) =>
__self_0 == __arg1_0,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::hash::Hash for OwnerId {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
OwnerId::User(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
OwnerId::Team(__self_0) =>
::core::hash::Hash::hash(__self_0, state),
}
}
}Hash, #[automatically_derived]
impl ::core::fmt::Debug for OwnerId {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
OwnerId::User(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "User",
&__self_0),
OwnerId::Team(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Team",
&__self_0),
}
}
}Debug)]
13pub enum OwnerId {
14 User(UserId),
16 Team(TeamId),
18}
19
20#[derive(#[automatically_derived]
impl ::core::clone::Clone for Row {
#[inline]
fn clone(&self) -> Row {
Row {
crate_id: ::core::clone::Clone::clone(&self.crate_id),
owner_id: ::core::clone::Clone::clone(&self.owner_id),
created_at: ::core::clone::Clone::clone(&self.created_at),
created_by: ::core::clone::Clone::clone(&self.created_by),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Row {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field4_finish(f, "Row",
"crate_id", &self.crate_id, "owner_id", &self.owner_id,
"created_at", &self.created_at, "created_by", &&self.created_by)
}
}Debug)]
22#[non_exhaustive]
23pub struct Row {
24 pub crate_id: CrateId,
25 pub owner_id: OwnerId,
26 pub created_at: DateTime<Utc>,
27 pub created_by: Option<UserId>,
28}
29
30impl FromRecord for Row {
31 fn from_record(record: &StringRecord, headers: &StringRecord) -> Result<Self> {
32 de(record, headers)
33 }
34}
35
36fn de(record: &StringRecord, headers: &StringRecord) -> Result<Row> {
37 #[derive(#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for Record {
fn deserialize<__D>(__deserializer: __D)
-> _serde::__private228::Result<Self, __D::Error> where
__D: _serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
#[doc(hidden)]
enum __Field {
__field0,
__field1,
__field2,
__field3,
__field4,
}
#[doc(hidden)]
struct __FieldVisitor;
#[automatically_derived]
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
type Value = __Field;
fn expecting(&self,
__formatter: &mut _serde::__private228::Formatter)
-> _serde::__private228::fmt::Result {
_serde::__private228::Formatter::write_str(__formatter,
"field identifier")
}
fn visit_u64<__E>(self, __value: u64)
-> _serde::__private228::Result<Self::Value, __E> where
__E: _serde::de::Error {
match __value {
0u64 => _serde::__private228::Ok(__Field::__field0),
1u64 => _serde::__private228::Ok(__Field::__field1),
2u64 => _serde::__private228::Ok(__Field::__field2),
3u64 => _serde::__private228::Ok(__Field::__field3),
4u64 => _serde::__private228::Ok(__Field::__field4),
_ =>
_serde::__private228::Err(_serde::de::Error::invalid_value(_serde::de::Unexpected::Unsigned(__value),
&"field index 0 <= i < 5")),
}
}
fn visit_str<__E>(self, __value: &str)
-> _serde::__private228::Result<Self::Value, __E> where
__E: _serde::de::Error {
match __value {
"crate_id" => _serde::__private228::Ok(__Field::__field0),
"created_at" => _serde::__private228::Ok(__Field::__field1),
"created_by" => _serde::__private228::Ok(__Field::__field2),
"owner_id" => _serde::__private228::Ok(__Field::__field3),
"owner_kind" => _serde::__private228::Ok(__Field::__field4),
_ => {
_serde::__private228::Err(_serde::de::Error::unknown_field(__value,
FIELDS))
}
}
}
fn visit_bytes<__E>(self, __value: &[u8])
-> _serde::__private228::Result<Self::Value, __E> where
__E: _serde::de::Error {
match __value {
b"crate_id" => _serde::__private228::Ok(__Field::__field0),
b"created_at" =>
_serde::__private228::Ok(__Field::__field1),
b"created_by" =>
_serde::__private228::Ok(__Field::__field2),
b"owner_id" => _serde::__private228::Ok(__Field::__field3),
b"owner_kind" =>
_serde::__private228::Ok(__Field::__field4),
_ => {
let __value =
&_serde::__private228::from_utf8_lossy(__value);
_serde::__private228::Err(_serde::de::Error::unknown_field(__value,
FIELDS))
}
}
}
}
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for __Field {
#[inline]
fn deserialize<__D>(__deserializer: __D)
-> _serde::__private228::Result<Self, __D::Error> where
__D: _serde::Deserializer<'de> {
_serde::Deserializer::deserialize_identifier(__deserializer,
__FieldVisitor)
}
}
#[doc(hidden)]
struct __Visitor<'de> {
marker: _serde::__private228::PhantomData<Record>,
lifetime: _serde::__private228::PhantomData<&'de ()>,
}
#[automatically_derived]
impl<'de> _serde::de::Visitor<'de> for __Visitor<'de> {
type Value = Record;
fn expecting(&self,
__formatter: &mut _serde::__private228::Formatter)
-> _serde::__private228::fmt::Result {
_serde::__private228::Formatter::write_str(__formatter,
"struct Record")
}
#[inline]
fn visit_seq<__A>(self, mut __seq: __A)
-> _serde::__private228::Result<Self::Value, __A::Error>
where __A: _serde::de::SeqAccess<'de> {
let __field0 =
match _serde::de::SeqAccess::next_element::<CrateId>(&mut __seq)?
{
_serde::__private228::Some(__value) => __value,
_serde::__private228::None =>
return _serde::__private228::Err(_serde::de::Error::invalid_length(0usize,
&"struct Record with 5 elements")),
};
let __field1 =
match {
#[doc(hidden)]
struct __DeserializeWith<'de> {
value: DateTime<Utc>,
phantom: _serde::__private228::PhantomData<Record>,
lifetime: _serde::__private228::PhantomData<&'de ()>,
}
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for
__DeserializeWith<'de> {
fn deserialize<__D>(__deserializer: __D)
-> _serde::__private228::Result<Self, __D::Error> where
__D: _serde::Deserializer<'de> {
_serde::__private228::Ok(__DeserializeWith {
value: crate::datetime::de(__deserializer)?,
phantom: _serde::__private228::PhantomData,
lifetime: _serde::__private228::PhantomData,
})
}
}
_serde::__private228::Option::map(_serde::de::SeqAccess::next_element::<__DeserializeWith<'de>>(&mut __seq)?,
|__wrap| __wrap.value)
} {
_serde::__private228::Some(__value) => __value,
_serde::__private228::None =>
return _serde::__private228::Err(_serde::de::Error::invalid_length(1usize,
&"struct Record with 5 elements")),
};
let __field2 =
match _serde::de::SeqAccess::next_element::<Option<UserId>>(&mut __seq)?
{
_serde::__private228::Some(__value) => __value,
_serde::__private228::None =>
return _serde::__private228::Err(_serde::de::Error::invalid_length(2usize,
&"struct Record with 5 elements")),
};
let __field3 =
match _serde::de::SeqAccess::next_element::<u32>(&mut __seq)?
{
_serde::__private228::Some(__value) => __value,
_serde::__private228::None =>
return _serde::__private228::Err(_serde::de::Error::invalid_length(3usize,
&"struct Record with 5 elements")),
};
let __field4 =
match _serde::de::SeqAccess::next_element::<u8>(&mut __seq)?
{
_serde::__private228::Some(__value) => __value,
_serde::__private228::None =>
return _serde::__private228::Err(_serde::de::Error::invalid_length(4usize,
&"struct Record with 5 elements")),
};
_serde::__private228::Ok(Record {
crate_id: __field0,
created_at: __field1,
created_by: __field2,
owner_id: __field3,
owner_kind: __field4,
})
}
#[inline]
fn visit_map<__A>(self, mut __map: __A)
-> _serde::__private228::Result<Self::Value, __A::Error>
where __A: _serde::de::MapAccess<'de> {
let mut __field0: _serde::__private228::Option<CrateId> =
_serde::__private228::None;
let mut __field1:
_serde::__private228::Option<DateTime<Utc>> =
_serde::__private228::None;
let mut __field2:
_serde::__private228::Option<Option<UserId>> =
_serde::__private228::None;
let mut __field3: _serde::__private228::Option<u32> =
_serde::__private228::None;
let mut __field4: _serde::__private228::Option<u8> =
_serde::__private228::None;
while let _serde::__private228::Some(__key) =
_serde::de::MapAccess::next_key::<__Field>(&mut __map)? {
match __key {
__Field::__field0 => {
if _serde::__private228::Option::is_some(&__field0) {
return _serde::__private228::Err(<__A::Error as
_serde::de::Error>::duplicate_field("crate_id"));
}
__field0 =
_serde::__private228::Some(_serde::de::MapAccess::next_value::<CrateId>(&mut __map)?);
}
__Field::__field1 => {
if _serde::__private228::Option::is_some(&__field1) {
return _serde::__private228::Err(<__A::Error as
_serde::de::Error>::duplicate_field("created_at"));
}
__field1 =
_serde::__private228::Some({
#[doc(hidden)]
struct __DeserializeWith<'de> {
value: DateTime<Utc>,
phantom: _serde::__private228::PhantomData<Record>,
lifetime: _serde::__private228::PhantomData<&'de ()>,
}
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for
__DeserializeWith<'de> {
fn deserialize<__D>(__deserializer: __D)
-> _serde::__private228::Result<Self, __D::Error> where
__D: _serde::Deserializer<'de> {
_serde::__private228::Ok(__DeserializeWith {
value: crate::datetime::de(__deserializer)?,
phantom: _serde::__private228::PhantomData,
lifetime: _serde::__private228::PhantomData,
})
}
}
match _serde::de::MapAccess::next_value::<__DeserializeWith<'de>>(&mut __map)
{
_serde::__private228::Ok(__wrapper) => __wrapper.value,
_serde::__private228::Err(__err) => {
return _serde::__private228::Err(__err);
}
}
});
}
__Field::__field2 => {
if _serde::__private228::Option::is_some(&__field2) {
return _serde::__private228::Err(<__A::Error as
_serde::de::Error>::duplicate_field("created_by"));
}
__field2 =
_serde::__private228::Some(_serde::de::MapAccess::next_value::<Option<UserId>>(&mut __map)?);
}
__Field::__field3 => {
if _serde::__private228::Option::is_some(&__field3) {
return _serde::__private228::Err(<__A::Error as
_serde::de::Error>::duplicate_field("owner_id"));
}
__field3 =
_serde::__private228::Some(_serde::de::MapAccess::next_value::<u32>(&mut __map)?);
}
__Field::__field4 => {
if _serde::__private228::Option::is_some(&__field4) {
return _serde::__private228::Err(<__A::Error as
_serde::de::Error>::duplicate_field("owner_kind"));
}
__field4 =
_serde::__private228::Some(_serde::de::MapAccess::next_value::<u8>(&mut __map)?);
}
}
}
let __field0 =
match __field0 {
_serde::__private228::Some(__field0) => __field0,
_serde::__private228::None =>
_serde::__private228::de::missing_field("crate_id")?,
};
let __field1 =
match __field1 {
_serde::__private228::Some(__field1) => __field1,
_serde::__private228::None =>
return _serde::__private228::Err(<__A::Error as
_serde::de::Error>::missing_field("created_at")),
};
let __field2 =
match __field2 {
_serde::__private228::Some(__field2) => __field2,
_serde::__private228::None =>
_serde::__private228::de::missing_field("created_by")?,
};
let __field3 =
match __field3 {
_serde::__private228::Some(__field3) => __field3,
_serde::__private228::None =>
_serde::__private228::de::missing_field("owner_id")?,
};
let __field4 =
match __field4 {
_serde::__private228::Some(__field4) => __field4,
_serde::__private228::None =>
_serde::__private228::de::missing_field("owner_kind")?,
};
_serde::__private228::Ok(Record {
crate_id: __field0,
created_at: __field1,
created_by: __field2,
owner_id: __field3,
owner_kind: __field4,
})
}
}
#[doc(hidden)]
const FIELDS: &'static [&'static str] =
&["crate_id", "created_at", "created_by", "owner_id",
"owner_kind"];
_serde::Deserializer::deserialize_struct(__deserializer,
"Record", FIELDS,
__Visitor {
marker: _serde::__private228::PhantomData::<Record>,
lifetime: _serde::__private228::PhantomData,
})
}
}
};Deserialize)]
38 #[serde(deny_unknown_fields)]
39 struct Record {
40 crate_id: CrateId,
41 #[serde(deserialize_with = "crate::datetime::de")]
42 created_at: DateTime<Utc>,
43 created_by: Option<UserId>,
44 owner_id: u32,
45 owner_kind: u8,
46 }
47
48 let record: Record = record.deserialize(Some(headers)).map_err(err)?;
49
50 let owner_id = match record.owner_kind {
51 0 => OwnerId::User(UserId(record.owner_id)),
52 1 => OwnerId::Team(TeamId(record.owner_id)),
53 other => {
54 return Err(err(format_args!("unrecognized crate_owners.csv owner_kind: {0}", other)format_args!(
55 "unrecognized crate_owners.csv owner_kind: {}",
56 other,
57 )))
58 }
59 };
60
61 Ok(Row {
62 crate_id: record.crate_id,
63 created_at: record.created_at,
64 created_by: record.created_by,
65 owner_id,
66 })
67}
68
69impl PartialEq<UserId> for OwnerId {
70 fn eq(&self, other: &UserId) -> bool {
71 match self {
72 OwnerId::User(user_id) => user_id == other,
73 OwnerId::Team(_) => false,
74 }
75 }
76}
77
78impl PartialEq<TeamId> for OwnerId {
79 fn eq(&self, other: &TeamId) -> bool {
80 match self {
81 OwnerId::User(_) => false,
82 OwnerId::Team(team_id) => team_id == other,
83 }
84 }
85}
86
87impl PartialEq<OwnerId> for UserId {
88 fn eq(&self, other: &OwnerId) -> bool {
89 other == self
90 }
91}
92
93impl PartialEq<OwnerId> for TeamId {
94 fn eq(&self, other: &OwnerId) -> bool {
95 other == self
96 }
97}