Skip to content

Commit

Permalink
Merge pull request #57 from SpringQL/feat/spring_open-takes-reference
Browse files Browse the repository at this point in the history
feat: take reference instead of owned value for spring_open() to make C API more natural
  • Loading branch information
laysakura committed Mar 28, 2022
2 parents 6d908b0 + 6524edc commit dece243
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog][Keep a Changelog] and this project adh

## [Unreleased]

## [v0.3.0]

### Changed

- `spring_open()` and `SpringPipelineHL::new()` are changed to take `SpringConfig`'s reference instead of owned value.

## [v0.2.0]

### Added
Expand Down Expand Up @@ -43,6 +49,7 @@ The format is based on [Keep a Changelog][Keep a Changelog] and this project adh
<!-- Versions -->
[Unreleased]: https://github.com/SpringQL/SpringQL/compare/v0.2.0...HEAD
[Released]: https://github.com/SpringQL/SpringQL/releases
[v0.3.0]: https://github.com/SpringQL/SpringQL/compare/v0.2.0...v0.3.0
[v0.2.0]: https://github.com/SpringQL/SpringQL/compare/v0.1.1...v0.2.0
[v0.1.1]: https://github.com/SpringQL/SpringQL/compare/v0.1.0...v0.1.1
[v0.1.0]: https://github.com/SpringQL/SpringQL/releases/v0.1.0
2 changes: 1 addition & 1 deletion springql-core/examples/demo_pipeline.rs
Expand Up @@ -78,7 +78,7 @@ fn main() {
let sink_engine_wheel_speed = ForeignSink::start().unwrap();
let sink_vehicle_speed = ForeignSink::start().unwrap();

let pipeline = SpringPipelineHL::new(SpringConfig::default()).unwrap();
let pipeline = SpringPipelineHL::new(&SpringConfig::default()).unwrap();
pipeline
.command(
"
Expand Down
2 changes: 1 addition & 1 deletion springql-core/src/api/high_level_rs.rs
Expand Up @@ -13,7 +13,7 @@ pub struct SpringPipelineHL(SpringPipeline);

impl SpringPipelineHL {
/// Creates and open an in-process stream pipeline.
pub fn new(config: SpringConfig) -> Result<Self> {
pub fn new(config: &SpringConfig) -> Result<Self> {
let low_level = spring_open(config)?;
Ok(Self(low_level))
}
Expand Down
4 changes: 2 additions & 2 deletions springql-core/src/api/low_level_rs.rs
Expand Up @@ -53,10 +53,10 @@ impl From<SinkRow> for SpringRow {
}

/// Creates and open an in-process stream pipeline.
pub fn spring_open(config: SpringConfig) -> Result<SpringPipeline> {
pub fn spring_open(config: &SpringConfig) -> Result<SpringPipeline> {
setup_logger();

let engine = EngineMutex::new(&config);
let engine = EngineMutex::new(config);
let sql_processor = SqlProcessor::default();

Ok(SpringPipeline {
Expand Down
5 changes: 3 additions & 2 deletions springql-core/tests/feat_spring_open_twice.rs
Expand Up @@ -4,6 +4,7 @@ use springql_core::low_level_rs::{spring_config_default, spring_open};

#[test]
fn test_spring_open_twice() {
let _ = spring_open(spring_config_default()).unwrap();
let _ = spring_open(spring_config_default()).unwrap();
let config = spring_config_default();
let _ = spring_open(&config).unwrap();
let _ = spring_open(&config).unwrap();
}
4 changes: 2 additions & 2 deletions springql-core/tests/test_support/mod.rs
Expand Up @@ -10,7 +10,7 @@ use springql_foreign_service::sink::ForeignSink;

#[allow(dead_code)]
pub(crate) fn apply_ddls(ddls: &[String], config: SpringConfig) -> SpringPipelineHL {
let pipeline = SpringPipelineHL::new(config).unwrap();
let pipeline = SpringPipelineHL::new(&config).unwrap();
for ddl in ddls {
pipeline.command(ddl).unwrap();
}
Expand All @@ -19,7 +19,7 @@ pub(crate) fn apply_ddls(ddls: &[String], config: SpringConfig) -> SpringPipelin

#[allow(dead_code)]
pub(crate) fn apply_ddls_low_level(ddls: &[String], config: SpringConfig) -> SpringPipeline {
let pipeline = spring_open(config).unwrap();
let pipeline = spring_open(&config).unwrap();
for ddl in ddls {
spring_command(&pipeline, ddl).unwrap();
}
Expand Down

0 comments on commit dece243

Please sign in to comment.