ronantakizawa/codereview-bench huggingface dataset:
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
        SDL_UnlockSurface(state->intermediate_surface);

        was_error = false;
    }

done:
    if (closeio && dst) {
        if (!SDL_CloseIO(dst)) {
            was_error = true;
        }
    }
    if (was_error) {
        return false;
    }
    return true;
}

bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
{
    bool result = true;
    SaveBmpState state;
    if (!init_SaveBmpState(&state, surface)) {
        return false;
    }
    CHECK_PARAM(!dst) {
        result = false;
        goto done;
    }
    result = SDL_SaveBMP_state_IO(&state, dst, closeio);
done:
    deinit_SaveBmpState(&state);
    return result;
}

bool SDL_SaveBMP(SDL_Surface *surface, const char *file)
{
    SaveBmpState state;
    if (!init_SaveBmpState(&state, surface)) {
        return false;
    }

    SDL_IOStream *stream = SDL_IOFromFile(file, "wb");
    if (!stream) {
        return false;
    }

    bool result = SDL_SaveBMP_state_IO(&state, stream, true);
    deinit_SaveBmpState(&state);
    return result;
}


Review comment (suggestion):
```suggestion
        result = SDL_InvalidParamError("dst");
```

Code after:

        was_error = false;
    }

done:
    if (closeio && dst) {
        if (!SDL_CloseIO(dst)) {
            was_error = true;
        }
    }
    if (was_error) {
        return false;
    }
    return true;
}

bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
{
    bool result = true;
    BMPSaveState state;
    if (!InitBMPSaveState(&state, surface)) {
        return false;
    }
    CHECK_PARAM(!dst) {
        result = SDL_InvalidParamError("dst");
        goto done;
    }
    result = SDL_SaveBMP_IO_Internal(&state, dst, closeio);
done:
    FreeBMPSaveState(&state);
    return result;
}

bool SDL_SaveBMP(SDL_Surface *surface, const char *file)
{
    BMPSaveState state;
    if (!InitBMPSaveState(&state, surface)) {
        return false;
    }

    SDL_IOStream *stream = SDL_IOFromFile(file, "wb");
    if (!stream) {
        return false;
    }

    bool result = SDL_SaveBMP_IO_Internal(&state, stream, true);
    FreeBMPSaveState(&state);
    return result;
}
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
    }

    was_error = false;

done:
    if (was_error) {
        if (src) {
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} BMPSaveState;

static void FreeSaveBmpState(BMPSaveState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool InitSaveBmpState(BMPSaveState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        return SDL_InvalidParamError("surface");
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP

Review comment (suggestion):
```suggestion
static void FreeBMPSaveState(BMPSaveState *state)
```
Sorry, I didn't update this for the name change above...

Code after:
    }

    was_error = false;

done:
    if (was_error) {
        if (src) {
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} BMPSaveState;

static void FreeBMPSaveState(BMPSaveState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool InitBMPSaveState(BMPSaveState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        return SDL_InvalidParamError("surface");
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP
Repository: libsdl-org/SDL
File: src/video/SDL_bmp.c (C)

Code before:
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} BMPSaveState;

static void FreeSaveBmpState(BMPSaveState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool InitSaveBmpState(BMPSaveState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        return SDL_InvalidParamError("surface");
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP

    if (surface->palette && !state->save32bit) {
        if (SDL_BITSPERPIXEL(surface->format) == 8) {
            state->intermediate_surface = surface;
        } else {
            SDL_SetError("%u bpp BMP files not supported",
                         SDL_BITSPERPIXEL(surface->format));

Review comment (suggestion):
```suggestion
static bool InitBMPSaveState(BMPSaveState *state, SDL_Surface *surface)
```
ditto

Code after:
            SDL_SeekIO(src, fp_offset, SDL_IO_SEEK_SET);
        }
        SDL_DestroySurface(surface);
        surface = NULL;
    }
    if (closeio && src) {
        SDL_CloseIO(src);
    }
    return surface;
}

typedef struct {
    SDL_Surface *surface;
    SDL_Surface *intermediate_surface;
    bool save32bit;
    bool saveLegacyBMP;
} BMPSaveState;

static void FreeBMPSaveState(BMPSaveState *state)
{
    if (state->intermediate_surface && state->intermediate_surface != state->surface) {
        SDL_DestroySurface(state->intermediate_surface);
    }
}

static bool InitBMPSaveState(BMPSaveState *state, SDL_Surface *surface)
{
    state->surface = surface;
    state->intermediate_surface = NULL;
    state->save32bit = false;
    state->saveLegacyBMP = false;

    CHECK_PARAM(!SDL_SurfaceValid(surface)) {
        return SDL_InvalidParamError("surface");
    }

#ifdef SAVE_32BIT_BMP
    // We can save alpha information in a 32-bit BMP
    if (SDL_BITSPERPIXEL(surface->format) >= 8 &&
        (SDL_ISPIXELFORMAT_ALPHA(surface->format) ||
         (surface->map.info.flags & SDL_COPY_COLORKEY))) {
        state->save32bit = true;
    }
#endif // SAVE_32BIT_BMP

    if (surface->palette && !state->save32bit) {
        if (SDL_BITSPERPIXEL(surface->format) == 8) {
            state->intermediate_surface = surface;
        } else {
            SDL_SetError("%u bpp BMP files not supported",
                         SDL_BITSPERPIXEL(surface->format));
Repository: libsql/libsql
File: libsql-server/src/connection/libsql.rs (Rust)

Code before:
}

impl<T> std::fmt::Debug for LibSqlConnection<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.inner.try_lock() {
            Some(conn) => {
                write!(f, "{conn:?}")
            }
            None => write!(f, "<locked>"),
        }
    }
}

#[derive(Clone, Copy)]
pub struct InhibitCheckpointWalWrapper;

impl<W: Wal> WrapWal<W> for InhibitCheckpointWalWrapper {
    fn checkpoint<B: libsql_sys::wal::BusyHandler>(
        &mut self,
        _wrapped: &mut W,
        _db: &mut libsql_sys::wal::Sqlite3Db,
        _mode: libsql_sys::wal::CheckpointMode,
        _busy_handler: Option<&mut B>,
        _sync_flags: u32,
        _buf: &mut [u8],
    ) -> libsql_sys::wal::Result<(u32, u32)> {
        Err(rusqlite::ffi::Error::new(SQLITE_BUSY))
    }
}

pub type InhibitCheckpoint<T> = WrappedWal<InhibitCheckpointWalWrapper, T>;

// Opens a connection with checkpoint inhibited
pub fn open_conn<T>(
    path: &Path,
    wal_manager: T,
    flags: Option<OpenFlags>,
) -> Result<libsql_sys::Connection<InhibitCheckpoint<T::Wal>>, rusqlite::Error>
where
    T: WalManager,
{
    let flags = flags.unwrap_or(
        OpenFlags::SQLITE_OPEN_READ_WRITE
            | OpenFlags::SQLITE_OPEN_CREATE
            | OpenFlags::SQLITE_OPEN_URI
            | OpenFlags::SQLITE_OPEN_NO_MUTEX,
    );

    libsql_sys::Connection::open(
        path.join("data"),
        flags,

Review comment (bug):
let's put a log message here, debug level maybe? So that we can track if some connections get inhibited often

Code after:
}

impl<T> std::fmt::Debug for LibSqlConnection<T> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self.inner.try_lock() {
            Some(conn) => {
                write!(f, "{conn:?}")
            }
            None => write!(f, "<locked>"),
        }
    }
}

#[derive(Clone, Copy)]
pub struct InhibitCheckpointWalWrapper;

impl<W: Wal> WrapWal<W> for InhibitCheckpointWalWrapper {
    fn checkpoint<B: libsql_sys::wal::BusyHandler>(
        &mut self,
        _wrapped: &mut W,
        _db: &mut libsql_sys::wal::Sqlite3Db,
        _mode: libsql_sys::wal::CheckpointMode,
        _busy_handler: Option<&mut B>,
        _sync_flags: u32,
        _buf: &mut [u8],
    ) -> libsql_sys::wal::Result<(u32, u32)> {
        tracing::warn!(
            "chackpoint inhibited: this connection is not allowed to perform checkpoints"
        );
        Err(rusqlite::ffi::Error::new(SQLITE_BUSY))
    }
}

pub type InhibitCheckpoint<T> = WrappedWal<InhibitCheckpointWalWrapper, T>;

// Opens a connection with checkpoint inhibited
pub fn open_conn<T>(
    path: &Path,
    wal_manager: T,
    flags: Option<OpenFlags>,
) -> Result<libsql_sys::Connection<InhibitCheckpoint<T::Wal>>, rusqlite::Error>
where
    T: WalManager,
{
    let flags = flags.unwrap_or(
        OpenFlags::SQLITE_OPEN_READ_WRITE
            | OpenFlags::SQLITE_OPEN_CREATE
            | OpenFlags::SQLITE_OPEN_URI
            | OpenFlags::SQLITE_OPEN_NO_MUTEX,
    );
Repository: libsql/libsql
File: libsql-sqlite3/src/wal.c (C)

Code before:
           if (iFrame == 0) {
               continue;
           }
        }
        frames[iFrame] = iPageno;
    }
    walIteratorFree(pIter);
    if (rc != 0) {
        sqlite3_free(frames);
        return rc;
    }

    p->current = pWal->hdr.mxFrame;
    p->frames = frames;

    return SQLITE_OK;
}

static void walIteratorRevFree(struct WalIteratorRev *p) {
    p->current = 0;
    sqlite3_free(p->frames);
}

#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
/*
** Attempt to enable blocking locks. Blocking locks are enabled only if (a)
** they are supported by the VFS, and (b) the database handle is configured
** with a busy-timeout. Return 1 if blocking locks are successfully enabled,
** or 0 otherwise.
*/
static int walEnableBlocking(Wal *pWal){
  int res = 0;
  if( pWal->db ){
    int tmout = pWal->db->busyTimeout;
    if( tmout ){
      int rc;
      rc = sqlite3OsFileControl(
          pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout
      );
      res = (rc==SQLITE_OK);
    }
  }
  return res;
}

/*
** Disable blocking locks.
*/
static void walDisableBlocking(Wal *pWal){
  int tmout = 0;
  sqlite3OsFileControl(pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout);

Review comment (suggestion):
again, is it feasible to use `sqlite3DbFree` from the call site? It should be preferred whenever available

Code after:
         * then we replace it with the latest page with frame_no <= mxSafeFrame.
         */
        if (iFrame > mxSafeFrame && !ignoreFrameIfNewerExist) {
           rc = walFindFrame(pWal, iPageno, mxSafeFrame, &iFrame);
           if( rc!=SQLITE_OK ) break;
           if (iFrame == 0) {
               continue;
           }
        }
        frames[iFrame] = iPageno;
    }
    walIteratorFree(pIter);
    if (rc != 0) {
        sqlite3_free(frames);
        return rc;
    }

    p->current = pWal->hdr.mxFrame;
    p->frames = frames;

    return SQLITE_OK;
}

static void walIteratorRevFree(struct WalIteratorRev *p) {
    p->current = 0;
    sqlite3_free(p->frames);
}

#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
/*
** Attempt to enable blocking locks. Blocking locks are enabled only if (a)
** they are supported by the VFS, and (b) the database handle is configured
** with a busy-timeout. Return 1 if blocking locks are successfully enabled,
** or 0 otherwise.
*/
static int walEnableBlocking(Wal *pWal){
  int res = 0;
  if( pWal->db ){
    int tmout = pWal->db->busyTimeout;
    if( tmout ){
      int rc;
      rc = sqlite3OsFileControl(
          pWal->pDbFd, SQLITE_FCNTL_LOCK_TIMEOUT, (void*)&tmout
      );
      res = (rc==SQLITE_OK);
    }
  }
  return res;
}

/*
Repository: libsql/libsql
File: bindings/c/src/lib.rs (Rust)

Code before:
}

#[no_mangle]
pub unsafe extern "C" fn libsql_disconnect(conn: libsql_connection_t) {
    if conn.is_null() {
        return;
    }
    let _conn = unsafe { Box::from_raw(conn.get_ref_mut()) };
    // TODO close conn
}

#[no_mangle]
pub unsafe extern "C" fn libsql_prepare(
    sql: *const std::ffi::c_char,
    out_stmt: *mut libsql_stmt_t,
    out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int {
    let sql = unsafe { std::ffi::CStr::from_ptr(sql) };
    let sql = match sql.to_str() {
        Ok(sql) => sql,
        Err(e) => {
            set_err_msg(format!("Wrong SQL: {}", e), out_err_msg);
            return 1;
        }
    };
    let stmt = Box::leak(Box::new(libsql_stmt { stmt: stmt { sql: sql.to_string(), params: vec![]} }));
    *out_stmt = libsql_stmt_t::from(stmt);
    0
}

#[no_mangle]
pub unsafe extern "C" fn libsql_bind_int(
    stmt: libsql_stmt_t,
    idx: std::ffi::c_int,
    value: std::ffi::c_longlong,
    out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int {
    let idx: usize = match idx.try_into() {
        Ok(x) => x,
        Err(e) => {
            set_err_msg(format!("Wrong param index: {}", e), out_err_msg);
            return 1;
        }
    };
    let stmt = stmt.get_ref_mut();
    if stmt.params.len() < idx {
        stmt.params.resize(idx, libsql::Value::Null);
    }
    stmt.params[idx - 1] = value.into();
    0
}

Review comment (suggestion):
I think you just want to use this https://doc.rust-lang.org/stable/std/boxed/struct.Box.html#method.into_raw instead of leak.

Code after:
    0
}

#[no_mangle]
pub unsafe extern "C" fn libsql_disconnect(conn: libsql_connection_t) {
    if conn.is_null() {
        return;
    }
    let _conn = unsafe { Box::from_raw(conn.get_ref_mut()) };
    // TODO close conn
}

#[no_mangle]
pub unsafe extern "C" fn libsql_prepare(
    sql: *const std::ffi::c_char,
    out_stmt: *mut libsql_stmt_t,
    out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int {
    let sql = unsafe { std::ffi::CStr::from_ptr(sql) };
    let sql = match sql.to_str() {
        Ok(sql) => sql,
        Err(e) => {
            set_err_msg(format!("Wrong SQL: {}", e), out_err_msg);
            return 1;
        }
    };
    let stmt = Box::leak(Box::new(libsql_stmt {
        stmt: stmt {
            sql: sql.to_string(),
            params: vec![],
        },
    }));
    *out_stmt = libsql_stmt_t::from(stmt);
    0
}

#[no_mangle]
pub unsafe extern "C" fn libsql_bind_int(
    stmt: libsql_stmt_t,
    idx: std::ffi::c_int,
    value: std::ffi::c_longlong,
    out_err_msg: *mut *const std::ffi::c_char,
) -> std::ffi::c_int {
    let idx: usize = match idx.try_into() {
        Ok(x) => x,
        Err(e) => {
            set_err_msg(format!("Wrong param index: {}", e), out_err_msg);
            return 1;
        }
    };
    let stmt = stmt.get_ref_mut();
Repository: libsql/libsql
File: bindings/c/src/types.rs (Rust)

Code before:
pub struct libsql_rows_t {
    ptr: *const libsql_rows,
}

impl libsql_rows_t {
    pub fn null() -> libsql_rows_t {
        libsql_rows_t {
            ptr: std::ptr::null(),
        }
    }

    pub fn is_null(&self) -> bool {
        self.ptr.is_null()
    }

    pub fn get_ref(&self) -> &libsql::Rows {
        &unsafe { &*(self.ptr) }.result
    }

    #[allow(clippy::mut_from_ref)]
    pub fn get_ref_mut(&self) -> &mut libsql::Rows {
        let ptr_mut = self.ptr as *mut libsql_rows;
        &mut unsafe { &mut (*ptr_mut) }.result
    }
}

#[allow(clippy::from_over_into)]
impl From<&libsql_rows> for libsql_rows_t {
    fn from(value: &libsql_rows) -> Self {
        Self { ptr: value }
    }
}

#[allow(clippy::from_over_into)]
impl From<&mut libsql_rows> for libsql_rows_t {
    fn from(value: &mut libsql_rows) -> Self {
        Self { ptr: value }
    }
}

pub struct libsql_rows_future {
    pub(crate) result: libsql::RowsFuture,
}

#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_rows_future_t {
    ptr: *const libsql_rows_future,
}

impl libsql_rows_future_t {

Review comment (suggestion):
I think this needs to be marked unsafe, converting a &_ to a &mut _ is a UB and violates LLVM aliasing. So this likely should return the raw *mut pointer as well and not convert it back into a safe rust &mut 

Code after:
    pub stmt: stmt,
}

#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct libsql_stmt_t {
    ptr: *const libsql_stmt,
}

impl libsql_stmt_t {
    pub fn null() -> libsql_stmt_t {
        libsql_stmt_t {
            ptr: std::ptr::null(),
        }
    }

    pub fn is_null(&self) -> bool {
        self.ptr.is_null()
    }

    pub fn get_ref(&self) -> &stmt {
        &unsafe { &*self.ptr }.stmt
    }

    #[allow(clippy::mut_from_ref)]
    pub fn get_ref_mut(&self) -> &mut stmt {
        let ptr_mut = self.ptr as *mut libsql_stmt;
        &mut unsafe { &mut (*ptr_mut) }.stmt
    }
}

#[allow(clippy::from_over_into)]
impl From<&libsql_stmt> for libsql_stmt_t {
    fn from(value: &libsql_stmt) -> Self {
        Self { ptr: value }
    }
}

#[allow(clippy::from_over_into)]
impl From<&mut libsql_stmt> for libsql_stmt_t {
    fn from(value: &mut libsql_stmt) -> Self {
        Self { ptr: value }
    }
}

pub struct libsql_rows {
    pub(crate) result: libsql::Rows,
}

#[derive(Clone, Debug)]
#[repr(transparent)]
Repository: libsql/libsql
File: libsql-server/src/stats.rs (Rust)

Code before:
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct SlowestQuery {
    pub elapsed_ms: u64,
    pub query: String,
    pub rows_written: u64,
    pub rows_read: u64,
}

impl SlowestQuery {
    pub fn new(query: String, elapsed_ms: u64, rows_read: u64, rows_written: u64) -> Self {
        Self {
            elapsed_ms,
            query,
            rows_read,
            rows_written,
        }
    }
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Stats {
    #[serde(skip)]
    namespace: NamespaceName,

    #[serde(default)]
    id: Uuid,
    #[serde(default)]
    rows_written: AtomicU64,
    #[serde(default)]
    rows_read: AtomicU64,
    #[serde(default)]
    storage_bytes_used: AtomicU64,
    // number of write requests delegated from a replica to primary
    #[serde(default)]
    write_requests_delegated: AtomicU64,
    #[serde(default)]
    current_frame_no: AtomicU64,
    // Lowest value in currently stored top queries
    #[serde(default)]
    top_query_threshold: AtomicU64,
    #[serde(default)]
    top_queries: Arc<RwLock<BTreeSet<TopQuery>>>,
    // Lowest value in currently stored slowest queries
    #[serde(default)]
    slowest_query_threshold: AtomicU64,
    #[serde(default)]
    slowest_queries: Arc<RwLock<BTreeSet<SlowestQuery>>>,
}

impl Stats {
    pub async fn new(

Review comment (suggestion):
```suggestion
    #[serde(default)]
    id: Option<Uuid>,
```

This is how we would do it in rust

Code after:
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct SlowestQuery {
    pub elapsed_ms: u64,
    pub query: String,
    pub rows_written: u64,
    pub rows_read: u64,
}

impl SlowestQuery {
    pub fn new(query: String, elapsed_ms: u64, rows_read: u64, rows_written: u64) -> Self {
        Self {
            elapsed_ms,
            query,
            rows_read,
            rows_written,
        }
    }
}

#[derive(Debug, Default, Serialize, Deserialize)]
pub struct Stats {
    #[serde(skip)]
    namespace: NamespaceName,

    #[serde(default)]
    id: Option<Uuid>,
    #[serde(default)]
    rows_written: AtomicU64,
    #[serde(default)]
    rows_read: AtomicU64,
    #[serde(default)]
    storage_bytes_used: AtomicU64,
    // number of write requests delegated from a replica to primary
    #[serde(default)]
    write_requests_delegated: AtomicU64,
    #[serde(default)]
    current_frame_no: AtomicU64,
    // Lowest value in currently stored top queries
    #[serde(default)]
    top_query_threshold: AtomicU64,
    #[serde(default)]
    top_queries: Arc<RwLock<BTreeSet<TopQuery>>>,
    // Lowest value in currently stored slowest queries
    #[serde(default)]
    slowest_query_threshold: AtomicU64,
    #[serde(default)]
    slowest_queries: Arc<RwLock<BTreeSet<SlowestQuery>>>,
}

impl Stats {
    pub async fn new(
Repository: libsql/libsql
File: libsql/src/database.rs (Rust)

Code before:
#![allow(deprecated)]

mod builder;

pub use builder::Builder;

pub use libsql_sys::{Cipher, EncryptionConfig};

use std::fmt;

use crate::{Connection, Result};

cfg_core! {
    bitflags::bitflags! {
        /// Flags that can be passed to libsql to open a database in specific
        /// modes.
        #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
        #[repr(C)]
        pub struct OpenFlags: ::std::os::raw::c_int {
            const SQLITE_OPEN_READ_ONLY = libsql_sys::ffi::SQLITE_OPEN_READONLY;
            const SQLITE_OPEN_READ_WRITE = libsql_sys::ffi::SQLITE_OPEN_READWRITE;
            const SQLITE_OPEN_CREATE = libsql_sys::ffi::SQLITE_OPEN_CREATE;
        }
    }

    impl Default for OpenFlags {
        #[inline]
        fn default() -> OpenFlags {
            OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
        }
    }
}


Review comment (suggestion):
```suggestion
#[cfg(feature = "core")]
pub use libsql_sys::{Cipher, EncryptionConfig};
```

Code after:
#![allow(deprecated)]

mod builder;

pub use builder::Builder;

#[cfg(feature = "core")]
pub use libsql_sys::{Cipher, EncryptionConfig};

use std::fmt;

use crate::{Connection, Result};

cfg_core! {
    bitflags::bitflags! {
        /// Flags that can be passed to libsql to open a database in specific
        /// modes.
        #[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
        #[repr(C)]
        pub struct OpenFlags: ::std::os::raw::c_int {
            const SQLITE_OPEN_READ_ONLY = libsql_sys::ffi::SQLITE_OPEN_READONLY;
            const SQLITE_OPEN_READ_WRITE = libsql_sys::ffi::SQLITE_OPEN_READWRITE;
            const SQLITE_OPEN_CREATE = libsql_sys::ffi::SQLITE_OPEN_CREATE;
        }
    }

    impl Default for OpenFlags {
        #[inline]
        fn default() -> OpenFlags {
            OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE
        }
    }
}