Skip to content

Commit b5a538c

Browse files
committed
Initial commit
1 parent 701d81f commit b5a538c

File tree

6 files changed

+84
-2
lines changed

6 files changed

+84
-2
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

.rustfmt.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2+
max_width = 80
3+
tab_spaces = 2
4+
edition = "2018"

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "urlpattern"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
[dependencies]
7+
derive_more = "0.99.16"

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Deno Land
3+
Copyright (c) 2021 the Deno authors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
# urlpattern
2-
Rust implementation of the `URLPattern` web API
2+
3+
This crate implements the [`URLPattern` web API][urlpattern] in Rust. We aim to
4+
follow [the specification][spec] as closely as possible.
5+
6+
[urlpattern]: https://github.com/WICG/urlpattern
7+
[spec]: https://wicg.github.io/urlpattern/
8+
9+
## Contributing
10+
11+
We appreciate your help!
12+
13+
The code of conduct from the Deno repository applies here too:
14+
https://github.com/denoland/deno/blob/main/CODE_OF_CONDUCT.md.

src/lib.rs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
2+
3+
use derive_more::Display;
4+
5+
/// An error that occured during parsing.
6+
#[derive(Debug, Display)]
7+
pub enum ParseError {}
8+
9+
impl std::error::Error for ParseError {}
10+
11+
/// The structured input used to create a URL pattern.
12+
pub struct UrlPatternInit {
13+
protocol: String,
14+
username: String,
15+
password: String,
16+
hostname: String,
17+
port: String,
18+
pathname: String,
19+
search: String,
20+
hash: String,
21+
}
22+
23+
impl UrlPatternInit {
24+
pub fn parse(
25+
_pattern: &str,
26+
_base_url: Option<&str>,
27+
) -> Result<UrlPatternInit, ParseError> {
28+
Ok(UrlPatternInit {
29+
protocol: "".to_string(),
30+
username: "".to_string(),
31+
password: "".to_string(),
32+
hostname: "".to_string(),
33+
port: "".to_string(),
34+
pathname: "".to_string(),
35+
search: "".to_string(),
36+
hash: "".to_string(),
37+
})
38+
}
39+
}
40+
41+
/// A UrlPattern that can be matched against.
42+
pub struct UrlPattern {}
43+
44+
impl UrlPattern {
45+
/// Parse a [UrlPatternInit] and optionally a base url into a [UrlPattern].
46+
pub fn parse(
47+
_pattern_init: UrlPatternInit,
48+
_base_url: Option<&str>,
49+
) -> Result<UrlPattern, ParseError> {
50+
Ok(UrlPattern {})
51+
}
52+
53+
/// Test if a given input string (with optional base url), matches the pattern.
54+
pub fn test(&self, _input: &str, _base_url: Option<&str>) -> bool {
55+
false
56+
}
57+
}

0 commit comments

Comments
 (0)