Skip to content

Commit e9bd44f

Browse files
author
Joshua Nelson
committed
Add TpToken newtype
1 parent a4386dd commit e9bd44f

File tree

4 files changed

+99
-62
lines changed

4 files changed

+99
-62
lines changed

src/context_api/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! ```
2525
//! # #[macro_use] extern crate yottadb;
2626
//! use yottadb::context_api::Context;
27-
//! use yottadb::{YDB_NOTTP, DeleteType, YDBResult};
27+
//! use yottadb::{DeleteType, YDBResult};
2828
//!
2929
//! fn main() -> YDBResult<()> {
3030
//! let ctx = Context::new();
@@ -49,9 +49,9 @@ use std::ops::{Deref, DerefMut};
4949
use std::time::Duration;
5050
use std::fmt;
5151

52-
use crate::craw::{YDB_NOTTP, YDB_ERR_NODEEND};
52+
use crate::craw::YDB_ERR_NODEEND;
5353
use crate::simple_api::{
54-
self, tp_st, Key, YDBResult, YDBError, DataReturn, DeleteType, TransactionStatus,
54+
self, tp_st, Key, YDBResult, YDBError, DataReturn, DeleteType, TransactionStatus, TpToken,
5555
};
5656

5757
// Private macro to help make iterators
@@ -119,7 +119,7 @@ macro_rules! make_ckey {
119119
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
120120
struct ContextInternal {
121121
buffer: Option<Vec<u8>>,
122-
tptoken: u64,
122+
tptoken: TpToken,
123123
}
124124

125125
/// A struct that keeps track of the current transaction and error buffer.
@@ -192,7 +192,7 @@ impl Context {
192192
Context {
193193
context: Rc::new(RefCell::new(ContextInternal {
194194
buffer: Some(Vec::with_capacity(1024)),
195-
tptoken: YDB_NOTTP,
195+
tptoken: TpToken::default(),
196196
})),
197197
}
198198
}
@@ -234,7 +234,7 @@ impl Context {
234234
///
235235
/// # See also
236236
/// - [`Context::tp`](struct.Context.html#method.tp)
237-
pub fn tptoken(&self) -> u64 {
237+
pub fn tptoken(&self) -> TpToken {
238238
self.borrow().tptoken
239239
}
240240

@@ -348,7 +348,7 @@ impl Context {
348348
let result = tp_st(
349349
tptoken,
350350
Vec::with_capacity(50),
351-
|tptoken: u64| {
351+
|tptoken: TpToken| {
352352
self.context.borrow_mut().tptoken = tptoken;
353353
f(self)
354354
},

src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ pub mod context_api;
4646
pub mod craw;
4747
pub mod simple_api;
4848

49-
pub use craw::{YDB_NOTTP, YDB_ERR_GVUNDEF, YDB_ERR_LVUNDEF};
49+
pub use craw::{YDB_ERR_GVUNDEF, YDB_ERR_LVUNDEF};
5050
pub use simple_api::{
5151
call_in::{CallInDescriptor, CallInTableDescriptor},
52-
DataReturn, DeleteType, TransactionStatus, YDBError, YDBResult,
52+
DataReturn, DeleteType, TransactionStatus, TpToken, YDBError, YDBResult,
5353
};
54+
// This can't use `TpToken::default` because traits cannot have `const fn`
55+
/// The default transaction processing token if no transaction is in progress.
56+
pub const YDB_NOTTP: TpToken = TpToken(craw::YDB_NOTTP);
5457

5558
use std::os::raw::c_int;
5659
/// Cleans up the process connection/access to all databases and all yottadb data structures.

src/simple_api/call_in.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use std::ffi::{CString, CStr};
2121
use crate::craw::ci_name_descriptor;
22-
use super::{resize_call, YDBResult};
22+
use super::{resize_call, YDBResult, TpToken};
2323

2424
/// The descriptor for a call-in table opened with [`ci_tab_open_t`].
2525
///
@@ -66,7 +66,7 @@ pub struct CallInTableDescriptor(usize);
6666
/// # Ok(())
6767
/// # }
6868
pub fn ci_tab_open_t(
69-
tptoken: u64, err_buffer: Vec<u8>, file: &CStr,
69+
tptoken: TpToken, err_buffer: Vec<u8>, file: &CStr,
7070
) -> YDBResult<(CallInTableDescriptor, Vec<u8>)> {
7171
use crate::craw::ydb_ci_tab_open_t;
7272

@@ -107,7 +107,7 @@ pub fn ci_tab_open_t(
107107
/// # }
108108
/// ```
109109
pub fn ci_tab_switch_t(
110-
tptoken: u64, err_buffer: Vec<u8>, new_handle: CallInTableDescriptor,
110+
tptoken: TpToken, err_buffer: Vec<u8>, new_handle: CallInTableDescriptor,
111111
) -> YDBResult<(CallInTableDescriptor, Vec<u8>)> {
112112
use crate::craw::ydb_ci_tab_switch_t;
113113

@@ -160,7 +160,7 @@ pub fn ci_tab_switch_t(
160160
#[macro_export]
161161
macro_rules! ci_t {
162162
($tptoken: expr, $err_buffer: expr, $routine: expr $(, $args: expr)* $(,)?) => {{
163-
let tptoken: u64 = $tptoken;
163+
let tptoken: $crate::TpToken = $tptoken;
164164
let err_buffer: ::std::vec::Vec<u8> = $err_buffer;
165165
let routine: &::std::ffi::CStr = $routine;
166166

@@ -250,7 +250,7 @@ impl Drop for CallInDescriptor {
250250
#[macro_export]
251251
macro_rules! cip_t {
252252
($tptoken: expr, $err_buffer: expr, $routine: expr, $($args: expr),* $(,)?) => {{
253-
let tptoken: u64 = $tptoken;
253+
let tptoken: $crate::TpToken = $tptoken;
254254
let err_buffer: ::std::vec::Vec<u8> = $err_buffer;
255255
let routine: &mut $crate::simple_api::call_in::CallInDescriptor = $routine;
256256

0 commit comments

Comments
 (0)