Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F17416162
rfc_index.rs
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
895 B
Referenced Files
None
Subscribers
None
rfc_index.rs
View Options
use
std
::
error
::
Error
;
use
std
::
fs
;
use
std
::
path
::
Path
;
static
RFC_INDEX_URL
:
&
str
=
"https://www.ietf.org/download/rfc-index.txt"
;
pub
async
fn
get_rfc_index
(
source
:
Option
<
String
>
)
->
Result
<
String
,
Box
<
dyn
Error
>>
{
match
source
{
// Case 1 - A source file has been explicitly set
Some
(
file
)
=>
Ok
(
fs
::
read_to_string
(
&
file
)
?
.
parse
()
?
),
None
=>
{
if
Path
::
new
(
"rfc-index.txt"
).
exists
()
{
// Case 2 - The file rfc-index.txt can be found locally
Ok
(
fs
::
read_to_string
(
"rfc-index.txt"
)
?
.
parse
()
?
)
}
else
{
// Case 3 - Fetch the index remotely
Ok
(
fetch_rfc_index
().
await
?
)
}
}
}
}
async
fn
fetch_rfc_index
()
->
Result
<
String
,
Box
<
dyn
Error
>>
{
let
body
=
reqwest
::
get
(
RFC_INDEX_URL
)
.
await
?
.
text
()
.
await
?
;
Ok
(
body
)
}
File Metadata
Details
Attached
Mime Type
text/x-asm
Expires
Mon, Dec 15, 22:37 (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3242610
Default Alt Text
rfc_index.rs (895 B)
Attached To
Mode
rDS Nasqueron Datasources
Attached
Detach File
Event Timeline
Log In to Comment