11use crate :: domain:: time:: DateTime ;
2- use crate :: domain:: { Character , Cow , VisibleName } ;
32use crate :: errors:: Result ;
43use crate :: { app, domain} ;
54use anyhow:: { Context , anyhow} ;
@@ -26,7 +25,7 @@ impl Database {
2625}
2726
2827impl app:: Inventory for Database {
29- fn get ( & self , name : & VisibleName ) -> Result < Option < domain:: Cow > > {
28+ fn get ( & self , name : & domain :: VisibleName ) -> Result < Option < domain:: Cow > > {
3029 let db = self . db . lock ( ) . unwrap ( ) ;
3130
3231 let read_txn = db. begin_read ( ) ?;
@@ -48,7 +47,7 @@ impl app::Inventory for Database {
4847 }
4948 }
5049
51- fn list ( & self ) -> Result < Vec < Cow > > {
50+ fn list ( & self ) -> Result < Vec < domain :: Cow > > {
5251 let db = self . db . lock ( ) . unwrap ( ) ;
5352 let read_txn = db. begin_read ( ) ?;
5453 let mut cows = Vec :: new ( ) ;
@@ -68,7 +67,7 @@ impl app::Inventory for Database {
6867 }
6968 }
7069
71- fn update < F > ( & self , name : & VisibleName , f : F ) -> Result < ( ) >
70+ fn update < F > ( & self , name : & domain :: VisibleName , f : F ) -> Result < ( ) >
7271 where
7372 F : FnOnce ( Option < domain:: Cow > ) -> Result < Option < domain:: Cow > > ,
7473 {
@@ -119,44 +118,44 @@ impl From<domain::Cow> for PersistedCow {
119118 }
120119}
121120
122- impl TryInto < domain :: Cow > for PersistedCow {
121+ impl TryFrom < PersistedCow > for domain :: Cow {
123122 type Error = crate :: errors:: Error ;
124123
125- fn try_into ( self ) -> std:: result:: Result < domain :: Cow , Self :: Error > {
124+ fn try_from ( value : PersistedCow ) -> std:: result:: Result < Self , Self :: Error > {
126125 Ok ( domain:: Cow :: new_from_history (
127- self . name . try_into ( ) ?,
128- self . character . try_into ( ) ?,
129- match self . first_seen {
126+ value . name . try_into ( ) ?,
127+ value . character . try_into ( ) ?,
128+ match value . first_seen {
130129 Some ( dt_str) => Some ( dt_str. try_into ( ) ?) ,
131130 None => None ,
132131 } ,
133- match self . last_seen {
132+ match value . last_seen {
134133 Some ( dt_str) => Some ( dt_str. try_into ( ) ?) ,
135134 None => None ,
136135 } ,
137- match self . last_checked {
136+ match value . last_checked {
138137 Some ( dt_str) => Some ( dt_str. try_into ( ) ?) ,
139138 None => None ,
140139 } ,
141140 ) )
142141 }
143142}
144143
145- impl From < & VisibleName > for String {
146- fn from ( value : & VisibleName ) -> Self {
144+ impl From < & domain :: VisibleName > for String {
145+ fn from ( value : & domain :: VisibleName ) -> Self {
147146 value. url ( ) . to_string ( )
148147 }
149148}
150149
151- impl TryInto < VisibleName > for String {
150+ impl TryFrom < String > for domain :: VisibleName {
152151 type Error = crate :: errors:: Error ;
153152
154- fn try_into ( self ) -> std:: result:: Result < VisibleName , Self :: Error > {
155- VisibleName :: new ( self )
153+ fn try_from ( value : String ) -> std:: result:: Result < domain :: VisibleName , Self :: Error > {
154+ domain :: VisibleName :: new ( value )
156155 }
157156}
158157
159- impl From < & Character > for String {
158+ impl From < & domain :: Character > for String {
160159 fn from ( value : & domain:: Character ) -> Self {
161160 match value {
162161 domain:: Character :: Brave => "brave" . to_string ( ) ,
@@ -165,13 +164,13 @@ impl From<&Character> for String {
165164 }
166165}
167166
168- impl TryFrom < String > for Character {
167+ impl TryFrom < String > for domain :: Character {
169168 type Error = crate :: errors:: Error ;
170169
171- fn try_from ( value : String ) -> std:: result:: Result < Character , Self :: Error > {
170+ fn try_from ( value : String ) -> std:: result:: Result < domain :: Character , Self :: Error > {
172171 match value. as_str ( ) {
173- "brave" => Ok ( Character :: Brave ) ,
174- "shy" => Ok ( Character :: Shy ) ,
172+ "brave" => Ok ( domain :: Character :: Brave ) ,
173+ "shy" => Ok ( domain :: Character :: Shy ) ,
175174 other => Err ( Self :: Error :: Unknown ( anyhow ! (
176175 "unknown character: {}" ,
177176 other
@@ -187,10 +186,10 @@ impl From<&DateTime> for String {
187186 }
188187}
189188
190- impl TryInto < DateTime > for String {
189+ impl TryFrom < String > for DateTime {
191190 type Error = crate :: errors:: Error ;
192191
193- fn try_into ( self ) -> std:: result:: Result < DateTime , Self :: Error > {
194- DateTime :: new_from_str ( & self , DT_FORMAT )
192+ fn try_from ( value : String ) -> std:: result:: Result < Self , Self :: Error > {
193+ DateTime :: new_from_str ( & value , DT_FORMAT )
195194 }
196195}
0 commit comments