A proposal for URL replacement
Created by: zonyitoo
Redox uses URL as resource locator, which makes it outstanding from the other OS that written in pure Rust. But the URL in Redox has the following syntax
scheme://nomatterwhatgoeshere
The content after :
will all be processed by the scheme
, so it is not actually a valid IANA URI, which is defined as
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
Redox does not need the query
and fragment
parts. So what we need is just scheme:param
. Then here is the proposal: CURIE
Curie's syntax is defined as
curie := [ [ prefix ] ':' ] reference
prefix := NCName
reference := irelative-ref (as defined in IRI)
irelative-ref = irelative-part [ "?" iquery ] [ "#" ifragment ]
irelative-part = "//" iauthority ipath-abempty
/ ipath-absolute
which meets the requirement of Redox.
Proposed implementation detail
Define two structs, Curie
and CurieBuf
just like std::path::{Path, PathBuf}
.
struct Curie<'a> {
prefix: Option<&'a str>,
reference: &'a str,
}
struct CurieBuf {
prefix: Option<String>,
reference: String,
}
Curie
is immutable and it could only be created from &str
, which would cover most use cases, such as
let path = Curie::new("file:/home/redox/helloworld");
let no_prefix = Curie::new("mystique_content");
The Curie::new
method just simply find the first :
from the &str
and slice it to construct the Curie
struct, which is cheap and won't involve any unnecessary memory allocation.
The CurieBuf
is the owned version of Curie
.