Skip to content

Commit 11bb133

Browse files
committed
any-ref changed to RwLock; ABI 0.0.9 ; tag 0.0.6
1 parent 3306cb0 commit 11bb133

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

.github/workflows/check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
- uses: calcit-lang/[email protected]
1818
with:
19-
version: "0.8.51"
19+
version: "0.8.52"
2020

2121
- uses: dtolnay/rust-toolchain@stable
2222
with:

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "calcit_regex"
3-
version = "0.0.5"
3+
version = "0.0.6"
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.6.5"
16+
cirru_edn = "0.6.6"
1717
# cirru_edn = { path = "/Users/chenyong/repo/cirru/edn.rs" }
1818
cirru_parser = "0.1.29"
1919
regex = "1.10.4"

calcit.cirru

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compact.cirru

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
{} (:package |regex)
3-
:configs $ {} (:init-fn |regex.test/main!) (:reload-fn |regex.test/reload!) (:version |0.0.5-a1)
3+
:configs $ {} (:init-fn |regex.test/main!) (:reload-fn |regex.test/reload!) (:version |0.0.6)
44
:modules $ []
55
:entries $ {}
66
:files $ {}

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::{cell::RefCell, sync::Arc};
1+
use std::sync::{Arc, RwLock};
22

33
use cirru_edn::{Edn, EdnAnyRef, EdnListView};
44
use regex::Regex;
55

66
#[no_mangle]
77
pub fn abi_version() -> String {
8-
String::from("0.0.8")
8+
String::from("0.0.9")
99
}
1010

1111
#[no_mangle]
@@ -14,7 +14,7 @@ pub fn re_pattern(args: Vec<Edn>) -> Result<Edn, String> {
1414
match &args[0] {
1515
Edn::Str(s) => match Regex::new(s) {
1616
Ok(pattern) => {
17-
let p = Arc::from(RefCell::new(pattern));
17+
let p = Arc::from(RwLock::new(pattern));
1818

1919
Ok(Edn::AnyRef(EdnAnyRef(p)))
2020
}
@@ -36,7 +36,7 @@ pub fn re_matches(args: Vec<Edn>) -> Result<Edn, String> {
3636
Err(e) => Err(format!("re-matches failed, {}", e)),
3737
},
3838
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
39-
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
39+
if let Some(pattern) = p.read().map_err(|e| e.to_string())?.downcast_ref::<Regex>() {
4040
Ok(Edn::Bool(pattern.is_match(s)))
4141
} else {
4242
Err(format!("re-matches expected a regex, got {:?}", p))
@@ -63,7 +63,7 @@ pub fn re_find_index(args: Vec<Edn>) -> Result<Edn, String> {
6363
}
6464
}
6565
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
66-
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
66+
if let Some(pattern) = p.read().map_err(|e| e.to_string())?.downcast_ref::<Regex>() {
6767
match pattern.find(s) {
6868
Some(matched) => Ok(Edn::Number(matched.start() as f64)),
6969
None => Ok(Edn::Number(-1.0)), // TODO maybe nil
@@ -97,7 +97,7 @@ pub fn re_find(args: Vec<Edn>) -> Result<Edn, String> {
9797
}
9898
}
9999
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
100-
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
100+
if let Some(pattern) = p.read().map_err(|e| e.to_string())?.downcast_ref::<Regex>() {
101101
let mut matched = pattern.find_iter(s);
102102
match matched.next() {
103103
Some(v) => Ok(Edn::str(v.as_str().to_string())),
@@ -129,7 +129,7 @@ pub fn re_find_all(args: Vec<Edn>) -> Result<Edn, String> {
129129
Err(e) => Err(format!("re-find-all failed, {}", e)),
130130
},
131131
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
132-
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
132+
if let Some(pattern) = p.read().map_err(|e| e.to_string())?.downcast_ref::<Regex>() {
133133
let mut ys: Vec<Edn> = vec![];
134134
for v in pattern.find_iter(s) {
135135
ys.push(Edn::Str(v.as_str().to_string().into()))
@@ -161,7 +161,7 @@ pub fn re_split(args: Vec<Edn>) -> Result<Edn, String> {
161161
Err(e) => Err(format!("re-split failed, {}", e)),
162162
},
163163
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p))) => {
164-
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
164+
if let Some(pattern) = p.read().map_err(|e| e.to_string())?.downcast_ref::<Regex>() {
165165
let mut ys: Vec<Edn> = vec![];
166166
for piece in pattern.split(s) {
167167
ys.push(Edn::str(piece));
@@ -187,7 +187,7 @@ pub fn re_replace_all(args: Vec<Edn>) -> Result<Edn, String> {
187187
Err(e) => Err(format!("re-replace-all failed, {}", e)),
188188
},
189189
(Edn::Str(s), Edn::AnyRef(EdnAnyRef(p)), Edn::Str(next)) => {
190-
if let Some(pattern) = p.borrow().downcast_ref::<Regex>() {
190+
if let Some(pattern) = p.read().map_err(|e| e.to_string())?.downcast_ref::<Regex>() {
191191
Ok(Edn::str(pattern.replace_all(s, &**next).into_owned()))
192192
} else {
193193
Err(format!("re-replace-all expected a regex, got {:?}", p))

0 commit comments

Comments
 (0)