Skip to content

Commit f3c3ebf

Browse files
committed
release v3.2.1 to github
1 parent a62e257 commit f3c3ebf

File tree

16 files changed

+1001
-122
lines changed

16 files changed

+1001
-122
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/target
22
.vscode
33
Cargo.lock
4-
4+
src/main.rs

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dolphindb"
3-
version = "3.2.0"
3+
version = "3.2.1"
44
edition = "2021"
55
license = "MIT OR Apache-2.0"
66
description = "A Rust native API for DolphinDB"

examples/data_forms.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use dolphindb::types::*;
2+
3+
fn main() {
4+
// create empty data forms
5+
let _v = Vector::<Int>::new();
6+
let _v = Vector::<Int>::with_capacity(1);
7+
let _s = Set::<Int>::new();
8+
let _s = Set::<Int>::with_capacity(1);
9+
// Value type of dictionary is ANY
10+
let _d = Dictionary::<Int>::new();
11+
let _d = Dictionary::<Int>::with_capacity(1);
12+
13+
let _v = Vector::<Int>::from_raw(&[1]);
14+
let _v = IntVector::from_raw(&[1]);
15+
16+
let _a = IntArrayVector::new();
17+
18+
// use data forms
19+
let mut v = IntVector::new();
20+
// Usage of dolphindb's Vector is similar to Vec<T>
21+
v.push(1.into());
22+
let _t = v[0];
23+
let mut s = Set::<Int>::new();
24+
// Usage of dolphindb's Set is similar to HashSet<T>
25+
s.insert(1.into());
26+
s.get(&Int::new(1));
27+
let mut d = Dictionary::<Int>::new();
28+
// Usage of dolphindb's Dictionary is similar to HashMap<T, Any>
29+
d.insert(1.into(), Int::new(2));
30+
d.insert(1.into(), Double::new(2.0));
31+
d.get(&Int::new(1));
32+
let mut a = IntArrayVector::new();
33+
a.push(vec![1, 2, 3]);
34+
}

examples/quick_start.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
use dolphindb::{client::ClientBuilder, types::*};
12
use std::collections::HashMap;
23

3-
use dolphindb::client::ClientBuilder;
4-
54
#[tokio::main]
65
async fn main() {
76
// Since the client supports multiple configurations, we provide the ClientBuilder utility class to assist in creating client objects.
@@ -18,19 +17,38 @@ async fn main() {
1817
// Here, a pair object is created on the server.
1918
let res = client.run_script("a = pair(`a, `b)").await.unwrap();
2019
// If the DolphinDB script does not return a value, the returned `res` is None.
21-
if let Some(ref c) = res {
22-
println!("{}", c);
20+
if let None = res {
21+
println!("This script has no return value.");
2322
}
2423
// If the DolphinDB script has a return value, the returned `res` is a ConstantImpl.
2524
let res = client.run_script("a").await.unwrap();
2625
if let Some(ref c) = res {
2726
println!("{}", c);
2827
}
2928

29+
// Another usage of the client is executing a DolphinDB function
30+
// To execute a function, you need the function name and it's argument list
31+
// A function may have no argument and a return value.
32+
let ver = client.run_function("version", &[]).await.unwrap().unwrap();
33+
println!("{ver}");
34+
// Or one argument
35+
let typestr = client
36+
.run_function("typestr", &[res.clone().unwrap()])
37+
.await
38+
.unwrap()
39+
.unwrap();
40+
println!("{typestr}");
41+
// Or more
42+
let sum = client
43+
.run_function("add", &[Int::new(1).into(), Int::new(2).into()])
44+
.await
45+
.unwrap()
46+
.unwrap();
47+
println!("{sum}");
48+
3049
// The client can also upload data from Rust to the server and generate a variable.
3150
let mut variables = HashMap::new();
3251
// In this case, the HashMap's key is the variable name, and the value is the variable wrapped in ConstantImpl.
3352
variables.insert("a".to_string(), res.unwrap().clone());
34-
// The client can also upload data from Rust to the server and generate a variable.
3553
client.upload(&variables).await.unwrap();
3654
}

examples/table.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.

examples/table_writer.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use dolphindb::{
2+
client::ClientBuilder,
3+
error::Error,
4+
types::{ConstantImpl, DoubleArrayVector, Int, IntVector, TableBuilder, VectorImpl},
5+
};
6+
7+
async fn table_writer() -> Result<(), Error> {
8+
let mut builder = ClientBuilder::new("127.0.0.1:8848");
9+
builder.with_auth(("admin", "123456"));
10+
let mut client = builder.connect().await.unwrap();
11+
12+
let mut prices = DoubleArrayVector::new();
13+
let price1 = vec![1.1, 2.2, 3.3];
14+
prices.push(price1);
15+
println!("{prices}");
16+
17+
// write one row
18+
let c_int = ConstantImpl::from(Int::new(1));
19+
let c_double_array_vector = ConstantImpl::Vector(VectorImpl::from(prices.clone()));
20+
let res = client
21+
.run_function("tableInsert{testTable}", &[c_int, c_double_array_vector])
22+
.await
23+
.unwrap()
24+
.unwrap();
25+
println!("{res}");
26+
27+
// write a table
28+
let price2 = vec![4.4, 5.5];
29+
prices.push(price2);
30+
let v_int = IntVector::from_raw(&[2, 3]).into();
31+
let v_double_array_vector = VectorImpl::from(prices);
32+
println!("{v_double_array_vector}");
33+
let mut builder = TableBuilder::new();
34+
builder.with_name("my_table".to_string());
35+
builder.with_contents(
36+
vec![v_int, v_double_array_vector],
37+
vec!["volume".to_string(), "price".to_string()],
38+
);
39+
let table = builder.build().unwrap();
40+
println!("{table}");
41+
let res = client
42+
.run_function("tableInsert{testTable}", &[table.into()])
43+
.await?
44+
.unwrap();
45+
println!("{res}");
46+
Ok(())
47+
}
48+
49+
#[tokio::main]
50+
async fn main() {
51+
table_writer().await.unwrap();
52+
}

examples/type_conversion.rs

Lines changed: 115 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,134 @@
1-
use dolphindb::{
2-
client::ClientBuilder,
3-
types::*,
4-
};
1+
use dolphindb::{client::ClientBuilder, types::*};
52
use std::collections::HashMap;
63

74
#[tokio::main]
85
async fn main() {
96
let mut builder = ClientBuilder::new("127.0.0.1:8848");
107
builder.with_auth(("admin", "123456"));
118
let mut client = builder.connect().await.unwrap();
12-
let mut variables = HashMap::new();
9+
let mut variables: HashMap<String, ConstantImpl> = HashMap::new();
1310

1411
// basic examples
15-
variables.insert("Int".to_string(), ConstantImpl::from(Int::new(1)));
16-
variables.insert("Double".to_string(), ConstantImpl::from(Double::new(1.0)));
17-
variables.insert("String".to_string(), ConstantImpl::from(DolphinString::new(String::from("1"))));
12+
variables.insert("Int".to_owned(), Int::new(1).into());
13+
variables.insert("Double".to_owned(), Double::new(1.0).into());
14+
variables.insert(
15+
"String".to_owned(),
16+
DolphinString::new("str".to_owned()).into(),
17+
);
1818

1919
// numeric types
20-
variables.insert("myVoid".to_string(), ConstantImpl::from(Void::new(())));
21-
variables.insert("myBool".to_string(), ConstantImpl::from(Bool::new(true)));
22-
variables.insert("myChar".to_string(), ConstantImpl::from(Char::new('a' as i8)));
23-
variables.insert("myShort".to_string(), ConstantImpl::from(Short::new(1i16)));
24-
variables.insert("myInt".to_string(), ConstantImpl::from(Int::new(2i32)));
25-
variables.insert("myLong".to_string(), ConstantImpl::from(Long::new(3i64)));
26-
variables.insert("myFloat".to_string(), ConstantImpl::from(Float::new(1.1f32)));
27-
variables.insert("myDouble".to_string(), ConstantImpl::from(Double::new(1.2f64)));
28-
variables.insert("myDecimal32".to_string(), ConstantImpl::from(Decimal32::from_raw(100i32, 1).unwrap()));
29-
variables.insert("myDecimal64".to_string(), ConstantImpl::from(Decimal64::from_raw(10000i64, 2).unwrap()));
30-
variables.insert("myDecimal128".to_string(), ConstantImpl::from(Decimal128::from_raw(1000000i128, 3).unwrap()));
20+
variables.insert("myVoid".to_owned(), Void::new(()).into());
21+
variables.insert("myBool".to_owned(), Bool::new(true).into());
22+
variables.insert("myChar".to_owned(), Char::new('a' as i8).into());
23+
variables.insert("myShort".to_owned(), Short::new(1i16).into());
24+
variables.insert("myInt".to_owned(), Int::new(2i32).into());
25+
variables.insert("myLong".to_owned(), Long::new(3i64).into());
26+
variables.insert("myFloat".to_owned(), Float::new(1.1f32).into());
27+
variables.insert("myDouble".to_owned(), Double::new(1.2f64).into());
28+
variables.insert(
29+
"myDecimal32".to_owned(),
30+
Decimal32::from_raw(100i32, 1).unwrap().into(),
31+
);
32+
variables.insert(
33+
"myDecimal64".to_owned(),
34+
Decimal64::from_raw(10000i64, 2).unwrap().into(),
35+
);
36+
variables.insert(
37+
"myDecimal128".to_owned(),
38+
Decimal128::from_raw(1000000i128, 3).unwrap().into(),
39+
);
3140

3241
// temporal types
33-
variables.insert("myDate".to_string(), ConstantImpl::from(Date::from_raw(20089).unwrap()));
34-
variables.insert("myTimestamp".to_string(), ConstantImpl::from(Timestamp::from_raw(1735660800_000i64).unwrap()));
35-
variables.insert("myNanoTimestamp".to_string(), ConstantImpl::from(NanoTimestamp::from_raw(1735660800_000_000_000i64).unwrap()));
36-
variables.insert("myMonth".to_string(), ConstantImpl::from(Month::from_ym(2025, 1).unwrap()));
37-
variables.insert("myMinute".to_string(), ConstantImpl::from(Minute::from_hm(17, 30).unwrap()));
38-
variables.insert("mySecond".to_string(), ConstantImpl::from(Second::from_hms(17, 30, 0).unwrap()));
39-
variables.insert("myTime".to_string(), ConstantImpl::from(Time::from_hms_milli(17, 30, 0, 100).unwrap()));
40-
variables.insert("myDateTime".to_string(), ConstantImpl::from(DateTime::from_raw(1735660800).unwrap()));
41-
variables.insert("myNanoTime".to_string(), ConstantImpl::from(NanoTime::from_hms_nano(17, 30,0,100_000_000u32).unwrap()));
42+
// unix timestamp (milliseconds)
43+
let unix_timestamp = 1735660800_000i64;
44+
variables.insert(
45+
"myDate".to_owned(),
46+
Date::from_raw(unix_timestamp / 86400_000).unwrap().into(),
47+
);
48+
variables.insert(
49+
"myDateTime".to_owned(),
50+
DateTime::from_raw((unix_timestamp / 1000) as i32)
51+
.unwrap()
52+
.into(),
53+
);
54+
variables.insert(
55+
"myTimestamp".to_owned(),
56+
Timestamp::from_raw(unix_timestamp).unwrap().into(),
57+
);
58+
variables.insert(
59+
"myNanoTimestamp".to_owned(),
60+
NanoTimestamp::from_raw(unix_timestamp * 1000_000)
61+
.unwrap()
62+
.into(),
63+
);
64+
variables.insert(
65+
"myMonth".to_owned(),
66+
Month::from_ym(2025, 1).unwrap().into(),
67+
);
68+
variables.insert(
69+
"myMinute".to_owned(),
70+
Minute::from_hm(17, 30).unwrap().into(),
71+
);
72+
variables.insert(
73+
"mySecond".to_owned(),
74+
Second::from_hms(17, 30, 0).unwrap().into(),
75+
);
76+
variables.insert(
77+
"myTime".to_owned(),
78+
Time::from_hms_milli(17, 30, 0, 100).unwrap().into(),
79+
);
80+
variables.insert(
81+
"myNanoTime".to_owned(),
82+
NanoTime::from_hms_nano(17, 30, 0, 100_000_000u32)
83+
.unwrap()
84+
.into(),
85+
);
86+
variables.insert(
87+
"myDateHour".to_owned(),
88+
DateHour::from_ymd_h(2025, 1, 1, 17).unwrap().into(),
89+
);
90+
91+
// other types
92+
variables.insert(
93+
"myString".to_owned(),
94+
DolphinString::new("str".to_owned()).into(),
95+
);
96+
variables.insert("myBlob".to_owned(), Blob::new(vec![b'a']).into());
97+
variables.insert("mySymbol".to_owned(), Symbol::new("1".to_owned()).into());
4298

4399
client.upload(&variables).await.unwrap();
44100

45101
// Void is not uploaded
46102
// println!("myVoid: {}", client.run_script("myVoid").await.unwrap().unwrap());
47-
println!("myBool: {}", client.run_script("myBool").await.unwrap().unwrap());
48-
println!("myChar: {}", client.run_script("myChar").await.unwrap().unwrap());
49-
println!("myShort: {}", client.run_script("myShort").await.unwrap().unwrap());
50-
println!("myInt: {}", client.run_script("myInt").await.unwrap().unwrap());
51-
println!("myLong: {}", client.run_script("myLong").await.unwrap().unwrap());
52-
println!("myFloat: {}", client.run_script("myFloat").await.unwrap().unwrap());
53-
println!("myDouble: {}", client.run_script("myDouble").await.unwrap().unwrap());
54-
println!("myDecimal32: {}", client.run_script("myDecimal32").await.unwrap().unwrap());
55-
println!("myDecimal64: {}", client.run_script("myDecimal64").await.unwrap().unwrap());
56-
println!("myDecimal128: {}", client.run_script("myDecimal128").await.unwrap().unwrap());
57-
println!("myDate: {}", client.run_script("myDate").await.unwrap().unwrap());
58-
println!("myTimestamp: {}", client.run_script("myTimestamp").await.unwrap().unwrap());
59-
println!("myNanoTimestamp: {}", client.run_script("myNanoTimestamp").await.unwrap().unwrap());
60-
println!("myMonth: {}", client.run_script("myMonth").await.unwrap().unwrap());
61-
println!("mySecond: {}", client.run_script("mySecond").await.unwrap().unwrap());
62-
println!("myTime: {}", client.run_script("myTime").await.unwrap().unwrap());
63-
println!("myDateTime: {}", client.run_script("myDateTime").await.unwrap().unwrap());
64-
println!("myNanoTime: {}", client.run_script("myNanoTime").await.unwrap().unwrap());
103+
let vars = [
104+
"myBool",
105+
"myChar",
106+
"myShort",
107+
"myInt",
108+
"myLong",
109+
"myFloat",
110+
"myDouble",
111+
"myDecimal32",
112+
"myDecimal64",
113+
"myDecimal128",
114+
"myDate",
115+
"myTimestamp",
116+
"myNanoTimestamp",
117+
"myDateTime",
118+
"myMonth",
119+
"mySecond",
120+
"myTime",
121+
"myNanoTime",
122+
"myDateHour",
123+
"myString",
124+
"myBlob",
125+
"mySymbol",
126+
];
127+
for var in vars {
128+
println!(
129+
"{}: {}",
130+
var,
131+
client.run_script(var).await.unwrap().unwrap()
132+
);
133+
}
65134
}

0 commit comments

Comments
 (0)