Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2707521
args.rs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
args.rs
View Options
pub
trait
Validatable
{
fn
from_id
(
id
:
usize
)
->
Self
;
fn
from_string
(
s
:
String
)
->
Self
;
fn
get_string
(
&
self
)
->
Option
<&
str
>
;
}
#[derive(Clone)]
pub
enum
Args
{
Id
(
usize
),
Script
(
String
),
}
#[derive(Clone)]
pub
enum
Item
{
Id
(
usize
),
Name
(
String
),
}
impl
Validatable
for
Args
{
fn
from_id
(
id
:
usize
)
->
Self
{
Args
::
Id
(
id
)
}
fn
from_string
(
s
:
String
)
->
Self
{
Args
::
Script
(
s
)
}
fn
get_string
(
&
self
)
->
Option
<&
str
>
{
match
self
{
Args
::
Id
(
_
)
=>
None
,
Args
::
Script
(
s
)
=>
Some
(
s
),
}
}
}
impl
Validatable
for
Item
{
fn
from_id
(
id
:
usize
)
->
Self
{
Item
::
Id
(
id
)
}
fn
from_string
(
s
:
String
)
->
Self
{
Item
::
Name
(
s
)
}
fn
get_string
(
&
self
)
->
Option
<&
str
>
{
match
self
{
Item
::
Id
(
_
)
=>
None
,
Item
::
Name
(
s
)
=>
Some
(
s
),
}
}
}
pub
fn
validate
<
T
:
Validatable
>
(
s
:
&
str
)
->
Result
<
T
,
String
>
{
if
let
Ok
(
id
)
=
s
.
parse
::
<
usize
>
()
{
Ok
(
T
::
from_id
(
id
))
}
else
{
Ok
(
T
::
from_string
(
s
.
to_owned
()))
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 1, 3:41 PM (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
491150
Default Alt Text
args.rs (1 KB)
Attached To
Mode
rPMC Process Management Controller
Attached
Detach File
Event Timeline
Log In to Comment