Skip to content

Commit ece6155

Browse files
committed
upgrade deps; tag 0.1.2
1 parent f951510 commit ece6155

File tree

4 files changed

+118
-42
lines changed

4 files changed

+118
-42
lines changed

.github/workflows/check.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@ jobs:
1111
name: Test
1212
runs-on: ubuntu-22.04
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

16-
- uses: supplypike/setup-bin@v3
16+
- uses: calcit-lang/setup-[email protected]
1717
with:
18-
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.0-a3/cr'
19-
name: 'cr'
20-
version: '0.8.0-a3'
21-
22-
- uses: supplypike/setup-bin@v3
23-
with:
24-
uri: 'https://github.com/calcit-lang/calcit/releases/download/0.8.0-a3/caps'
25-
name: 'caps'
26-
version: '0.8.0-a3'
18+
version: "0.8.50"
2719

2820
- uses: dtolnay/rust-toolchain@stable
2921
with:

Cargo.lock

Lines changed: 89 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "calcit_http"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
authors = ["jiyinyiyong <[email protected]>"]
55
edition = "2021"
66

@@ -13,7 +13,7 @@ crate-type = ["dylib"] # Creates dynamic lib
1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
cirru_edn = "0.5.0"
17-
cirru_parser = "0.1.25"
16+
cirru_edn = "0.6.3"
17+
cirru_parser = "0.1.29"
1818
tiny_http = "0.12.0"
1919
querystring = "1.1.0"

src/lib.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
use cirru_edn::Edn;
1+
use cirru_edn::{Edn, EdnMapView};
22
use std::collections::HashMap;
33
use std::sync::Arc;
44
use tiny_http::{Method, Response, Server};
55

66
struct HttpServerOptions {
77
port: u16,
8-
host: Box<str>,
8+
host: Arc<str>,
99
}
1010

1111
struct ResponseSkeleton {
1212
code: u16,
13-
headers: HashMap<Box<str>, Box<str>>,
14-
body: Box<str>,
13+
headers: HashMap<Arc<str>, Arc<str>>,
14+
body: Arc<str>,
1515
}
1616

1717
#[no_mangle]
1818
pub fn abi_version() -> String {
19-
String::from("0.0.6")
19+
String::from("0.0.7")
2020
}
2121

2222
#[no_mangle]
@@ -54,12 +54,12 @@ pub fn serve_http(
5454
for (k, v) in query {
5555
query_dict.insert(Edn::tag(k), v.into());
5656
}
57-
m.insert(Edn::tag("query"), Edn::Map(query_dict));
57+
m.insert(Edn::tag("query"), Edn::Map(EdnMapView(query_dict)));
5858
}
5959
None => {
6060
m.insert(Edn::tag("path"), url.into());
6161
m.insert(Edn::tag("querystring"), "".into());
62-
m.insert(Edn::tag("query"), Edn::Map(HashMap::new()));
62+
m.insert(Edn::tag("query"), Edn::Map(EdnMapView::default()));
6363
}
6464
}
6565

@@ -68,15 +68,15 @@ pub fn serve_http(
6868
for pair in request.headers() {
6969
headers.insert(Edn::tag(&pair.field.to_string()), Edn::str(pair.value.to_string()));
7070
}
71-
m.insert(Edn::tag("headers"), Edn::Map(headers));
71+
m.insert(Edn::tag("headers"), Edn::Map(EdnMapView(headers)));
7272

7373
if request.method() != &Method::Get {
7474
let mut content = String::new();
7575
request.as_reader().read_to_string(&mut content).unwrap();
76-
m.insert(Edn::tag("body"), Edn::Str(content.to_string().into_boxed_str()));
76+
m.insert(Edn::tag("body"), Edn::Str(content.to_string().into()));
7777
}
7878

79-
let info = Edn::Map(m);
79+
let info = Edn::Map(EdnMapView(m));
8080
let result = handler(vec![info])?;
8181
let res = parse_response(&result)?;
8282

@@ -95,12 +95,12 @@ fn parse_options(d: &Edn) -> Result<HttpServerOptions, String> {
9595
match d {
9696
Edn::Nil => Ok(HttpServerOptions {
9797
port: 4000,
98-
host: String::from("0.0.0.0").into_boxed_str(),
98+
host: Arc::from("0.0.0.0"),
9999
}),
100100
Edn::Map(m) => {
101101
let mut options = HttpServerOptions {
102102
port: 4000,
103-
host: String::from("0.0.0.0").into_boxed_str(),
103+
host: Arc::from("0.0.0.0"),
104104
};
105105
options.port = match m.get(&Edn::tag("port")) {
106106
Some(Edn::Number(port)) => *port as u16,
@@ -109,7 +109,7 @@ fn parse_options(d: &Edn) -> Result<HttpServerOptions, String> {
109109
};
110110
options.host = match m.get(&Edn::tag("host")) {
111111
Some(Edn::Str(host)) => host.to_owned(),
112-
None => String::from("0.0.0.0").into_boxed_str(),
112+
None => Arc::from("0.0.0.0"),
113113
a => return Err(format!("invalid config for host: {:?}", a)),
114114
};
115115
Ok(options)
@@ -124,7 +124,7 @@ fn parse_response(info: &Edn) -> Result<ResponseSkeleton, String> {
124124
let mut res = ResponseSkeleton {
125125
code: 200,
126126
headers: HashMap::new(),
127-
body: String::from("").into_boxed_str(),
127+
body: String::from("").into(),
128128
};
129129
res.code = match m.get(&Edn::tag("code")) {
130130
Some(Edn::Number(n)) => *n as u16,
@@ -133,26 +133,26 @@ fn parse_response(info: &Edn) -> Result<ResponseSkeleton, String> {
133133
};
134134
res.body = match m.get(&Edn::tag("body")) {
135135
Some(Edn::Str(s)) => s.to_owned(),
136-
Some(a) => a.to_string().into_boxed_str(),
137-
None => String::from("").into_boxed_str(),
136+
Some(a) => a.to_string().into(),
137+
None => String::from("").into(),
138138
};
139139
res.headers = match m.get(&Edn::tag("headers")) {
140140
Some(Edn::Map(m)) => {
141-
let mut hs: HashMap<Box<str>, Box<str>> = HashMap::new();
142-
for (k, v) in m {
143-
let k: Box<str> = if let Edn::Tag(s) = k {
144-
s.to_str()
141+
let mut hs: HashMap<Arc<str>, Arc<str>> = HashMap::new();
142+
for (k, v) in &m.0 {
143+
let k: Arc<str> = if let Edn::Tag(s) = k {
144+
Arc::from(s.ref_str())
145145
} else if let Edn::Str(s) = k {
146-
s.to_owned()
146+
Arc::from(&**s)
147147
} else {
148148
return Err(format!("invalid head entry: {}", k));
149149
};
150150
let value = if let Edn::Str(s2) = v {
151151
s2.to_owned()
152152
} else {
153-
v.to_string().into_boxed_str()
153+
v.to_string().into()
154154
};
155-
hs.insert(k, value);
155+
hs.insert(k, Arc::from(&*value));
156156
}
157157
hs
158158
}

0 commit comments

Comments
 (0)