A vector with a fixed capacity. (Rust)

Overview
Comments
  • Additional array sizes

    Additional array sizes

    We can add arbitrary requested array sizes, if you need a lot of them they may be feature gated to not bloat the crate's default size too much, but ask away here!

    So feel free to request sizes here; of course at some point in Rust's future we will have generics to cover this, and this kind of issue will be over!

    Ask Here 
    opened by bluss 20
  • Expose nodrop state through its API

    Expose nodrop state through its API

    When using NoDrop with no_drop_flag, there is no way to assert whether the inner value has been dropped or not. This PR exposes is_alive for containing structures that may also use unsafe_no_drop_flag themselves.

    opened by arcnmx 19
  • Add serde support

    Add serde support

    This implements serde support under the optional 'serde' feature, and adds unit tests to test said support.

    Serde will be optionally included for runtime, but is unfortunately required for running tests - as cargo does not have support for optional dev-dependencies. FEATURES="serde" is added to the travis config, as serde-support tests will not run without it.

    Fixes #54.

    opened by daboross 18
  • Implement a stop-gap “MaybeUninit” using ManuallyDrop

    Implement a stop-gap “MaybeUninit” using ManuallyDrop

    This is a cautious version of MaybeUninit, since we don't have one in libstd, based on ManuallyDrop.

    This moves ArrayVec to a nice, no size overhead implementation by default. It is understood this is not a perfect solution! We do the best we can with stable Rust, and will adopt std's MaybeUninit or equivalent as soon as it becomes available.

    ArrayString can already in this PR use what's been designated as the sound solution, since its backing array is Copy. See MaybeUninitCopy in the PR.

    I think we can enable the future stable MaybeUninit equivalent conditionally, automatically, and don't need user visible API changes for that.

    This removes nodrop as a dependency, finally.

    Look here for previous discussion: https://github.com/bluss/arrayvec/pull/76#issuecomment-338380519

    Closes #86 Fixes #62

    help wanted breaking-change 
    opened by bluss 17
  • Give ArrayVec a const-fn constructor

    Give ArrayVec a const-fn constructor

    I'm not sure if this is even possible but it would be great if ArrayVec::new() would be a const fn and hence could be called in places where only constant expressions are allowed (of course behind some feature-flag since const-fn is still unstable).

    The reason I'd like this feature is that I work on embedded systems where it's typical to have all memory allocated statically, i.e. for a large buffer one would have something like

    static mut BUFFER: [u8; 4096] = [0; 4096];
    

    This works fine for arrays (and Copy types) but it would be great if I could also use an ArrayVec there. Again, not sure if it's even possible since mem::uninitialized() seems to not be a const-fn (although it should, I think) but maybe/hopefully I'm wrong. :)

    lazy_static! will not work AFAIK because on first invocation of the initialization code the value gets constructed on the stack which typically will not be large enough to hold that value, even temporarily.

    Thanks for considering this! :)

    opened by michael-p 17
  • Add ArrayVec.extend_from_slice and capacity_left

    Add ArrayVec.extend_from_slice and capacity_left

    This add two new public methods on ArrayVec:

    • extend_from_slice: extends the vector with a slice using a memcpy.
    • capacity_left: utility function for use with extend_from_slice, e.g. see https://github.com/bluss/arrayvec/commit/fa4e22fcbfa73d63ad0dcaedfbc5542cc259210b.

    This also changes the Write implementation to use extend_from_slice and another commit that removes some whitespace and empty lines.

    opened by Thomasdezeeuw 13
  • Use ManuallyDrop

    Use ManuallyDrop

    ManuallyDrop is stable in Rust 1.20 (not yet released).

    This is the official nodrop that arrayvec has been waiting a long time for; it's likely that we will use Rust 1.20 as the new required version from this point.

    enhancement 
    opened by bluss 13
  • Prepare 0.4, more vec-like api and error reform

    Prepare 0.4, more vec-like api and error reform

    push, insert etc

    With the goal of making arrayvec more of a "drop-in" for Vec, we realign the signatures methods .push(elt), .insert(index, elt) and .remove(index).

    pub fn push(&mut self, element: A::Item);
    pub fn insert(&mut self, index: usize, element: A::Item);
    pub fn remove(&mut self, index: usize) -> A::Item;
    pub fn swap_remove(&mut self, index: usize) -> A::Item;
    

    try_push etc

    Mimicing something like fallible allocation, we have the fallible new methods:

    pub fn try_push(&mut self, element: A::Item) -> Result<(), CapacityError<A::Item>>;
    pub fn try_insert(&mut self, index: usize, element: A::Item) -> Result<(), CapacityError<A::Item>>;
    

    Notice that try_insert still panics if index is out of bounds.

    pop_at etc

    Mimicing .pop(), we have new “checked” versions of remove, swap_remove:

    pub fn pop_at(&mut self, index: usize) -> Option<A::Item>;
    pub fn swap_pop(&mut self, index: usize) -> Option<A::Item>;
    

    The rationale is: indexing out of bounds is not a regular runtime error, it's normally a contract violation. So when we introduce checked versions of such API, then we get “checked” versions that return Option. Non-presence is not necessarily an error.

    ArrayString::push etc

    • ArrayString: push, push_str now have the same signature as corresponding on String. New methods try_push, try_push_str.
    pub fn push(&mut self, c: char);
    pub fn try_push(&mut self, c: char) -> Result<(), CapacityError<char>>;
    pub fn push_str(&mut self, s: &str);
    pub fn try_push_str<'a>(&mut self, s: &'a str) -> Result<(), CapacityError<&'a str>>;
    

    Closes #46 Closes #45

    Miscellaneous Changes

    • odds is no longer a public dependency. We want the flexibility of dropping/upgrading this dep at will
    • Rust version changes
    opened by bluss 13
  • Add pop, truncate, and remove functions to ArrayString.

    Add pop, truncate, and remove functions to ArrayString.

    Fixes #66

    This seemed "too easy" as I basically copied stuff from libstd (with tweaks to the comments and slight tweaks to the code, noted in truncate.) So please let me know if I did anything wrong!

    opened by DenialAdams 12
  • Make zero-capacity ArrayVec a zero-sized type.

    Make zero-capacity ArrayVec a zero-sized type.

    This changes the Index for zero-length Arrays to be (), ensuring that they are zero-sized. Additionally, this adds bool as the index for singleton Arrays, to become compatible with future enum optimisations, which could potentially make Option<ArrayVec<[u8; 1]>> be 16 bits long instead of 32 once more vigorous enum discriminant optimisations are implemented.

    breaking-change 
    opened by clarfonthey 12
  • [ArrayString] Infallible constructor to fill inner array

    [ArrayString] Infallible constructor to fill inner array

    Some libraries like hex or bs58 expect a pre-filled buffer to operate on but ArrayString does not have an infallible constructor to create a fully filled inner array with "whatever".

    For example, the following made use of from_byte_string to make everything work as expected:

    let mut buffer = ArrayString::from_byte_string(&[b' '; SOME_LEN]).unwrap();
    let len = bs58::encode(some_data).into(&mut buffer[..]).unwrap_or_default();
    buffer.truncate(len);
    

    So do you mind me providing a PR to create something like ArrayString::new_filled()?

    opened by c410-f3r 10
  • Add `From<[T; LEN]>`

    Add `From<[T; LEN]>`

    We can use compile-time asserts to check that LEN <= CAP, and then only initialize the first LEN elements. So something like

    impl<T, const LEN: usize, const CAP: usize> From<[T; LEN]> for ArrayVec<T, CAP> {
      fn from(arr: [T; LEN]) -> Self {
        assert!(LEN <= CAP);
        // duplicate the rest of From<[T; LEN]> for ArrayVec<T, LEN> here
      }
    }
    
    opened by khoover 0
  • add const function to get &str from ArrayString

    add const function to get &str from ArrayString

    👋 Hello @bluss! Thank you for making this crate; it's super useful.

    I don't think we can dereference an ArrayString into a &str in a constant function right now, and traits like Deref seem unlikely to become const in the near future. Do you have an idea of the best way to support ArrayString -> string coercion in const functions?

    One way would just be to add a new method on ArrayString. I've done that in this PR in case it would be helpful; otherwise, let me know if you prefer me to open an issue for this.

    opened by DominicBurkart 0
  • Why are inherent associated functions of `ArrayVec` implemented via calls to trait-associated functions of `ArrayVecImpl` and not vice versa?

    Why are inherent associated functions of `ArrayVec` implemented via calls to trait-associated functions of `ArrayVecImpl` and not vice versa?

    Example:

    /// Return a mutable slice containing all elements of the vector.
    pub fn as_mut_slice(&mut self) -> &mut [T] {
        ArrayVecImpl::as_mut_slice(self)
    }
    

    AFAIK, const trait implementation is not landing soon. If ArrayVecImpl::as_mut_slice is defined via the call to the inherent function instead (i.e. if we reverse the implementation dependency), it will be possible to have easier feature-gated support for the const inherent associated function. Instead of the dependence on both const_trait_impl and const_mut_refs features there will be the dependency only on the latter.

    I guess it may be fine if you don't want to offer a feature-gated support for nightly const_mut_refs. However, I wouldn't mind to help you with reversing the dependency and opt-in support for the aforementioned nightly features. There's a popular crate const_fn that can help provide such support cleaner.

    opened by JohnScience 0
  • Why is `ArrayVec::new_const` needed instead of having const `ArrayVec::new`?

    Why is `ArrayVec::new_const` needed instead of having const `ArrayVec::new`?

    opened by JohnScience 0
  • Add Natvis visualizations for ArrayVec and ArrayString types

    Add Natvis visualizations for ArrayVec and ArrayString types

    This change adds Natvis visualizations for ArrayVec and ArrayString to help improve the debugging experience on Windows.

    Natvis is a framework that can be used to specify how types should be viewed under a supported debugger, such as the Windows debugger (WinDbg) and the Visual Studio debugger.

    When debugging types such as ArrayVec and/or ArrayString under a Windows debugger, the entries for these data structures are not always clear upon first glance. The internal data structure is shown, and it's not presented in a user-friendly way. The Rust compiler does have Natvis support for some types, but this is limited to some of the core libraries and not supported for external crates.

    https://github.com/rust-lang/rfcs/pull/3191 proposes adding support for embedding debugging visualizations such as Natvis in a Rust crate. This RFC has been approved, merged and implemented.

    This PR adds:

    Natvis visualizations for both ArrayVec and ArrayString. Tests for testing visualizers embedded in the arrayvec crate. Updates to the CI pipeline to ensure tests for visualizers are run so they do not break silently. A new debugger_visualizer feature for the arrayvec crate to enable the unstable debugger_visualizer Rust feature.

    opened by ridwanabdillahi 0
🚧 WIP 🚧 Vector database plugin for Postgres, written in Rust, specifically designed for LLM.

pgvecto.rs pgvecto.rs is a Postgres extension that provides vector similarity search functions. It is written in Rust and based on pgrx. Features cosi

TensorChord 74 Apr 26, 2023
Qdrant - vector similarity search engine with extended filtering support

Vector Similarity Search Engine with extended filtering support Qdrant (read: quadrant ) is a vector similarity search engine. It provides a productio

qdrant 3.5k Dec 30, 2022
FFSVM stands for "Really Fast Support Vector Machine"

In One Sentence You trained a SVM using libSVM, now you want the highest possible performance during (real-time) classification, like games or VR. Hig

Ralf Biedert 53 Nov 24, 2022
Msgpack serialization/deserialization library for Python, written in Rust using PyO3, and rust-msgpack. Reboot of orjson. msgpack.org[Python]

ormsgpack ormsgpack is a fast msgpack library for Python. It is a fork/reboot of orjson It serializes faster than msgpack-python and deserializes a bi

Aviram Hassan 139 Dec 30, 2022
Practice repo for learning Rust. Currently going through "Rust for JavaScript Developers" course.

rust-practice ?? Practice repo for learning Rust. Directories /rust-for-js-dev Files directed towards "Rust for JavaScript Developers" course. Thank y

Sammy Samkough 0 Dec 25, 2021
A Rust library with homemade machine learning models to classify the MNIST dataset. Built in an attempt to get familiar with advanced Rust concepts.

mnist-classifier Ideas UPDATED: Finish CLI Flags Parallelize conputationally intensive functions Class-based naive bayes README Image parsing Confusio

Neil Kaushikkar 0 Sep 2, 2021
🦀Rust Turkiye - Rust Dersleri

Rust Turkiye - Rust Dersleri CURIOSITY - Featuring Richard Feynman Bu repo Rust Turkiye tarafindan duzenlenen Rust Dersleri egitiminin alistirma ve ko

Theo M. Bulut 12 Jan 14, 2023
A Rust machine learning framework.

Linfa linfa (Italian) / sap (English): The vital circulating fluid of a plant. linfa aims to provide a comprehensive toolkit to build Machine Learning

Rust-ML 2.2k Jan 2, 2023
Machine Learning library for Rust

rusty-machine This library is no longer actively maintained. The crate is currently on version 0.5.4. Read the API Documentation to learn more. And he

James Lucas 1.2k Dec 31, 2022
Rust library for Self Organising Maps (SOM).

RusticSOM Rust library for Self Organising Maps (SOM). Using this Crate Add rusticsom as a dependency in Cargo.toml [dependencies] rusticsom = "1.1.0"

Avinash Shenoy 26 Oct 17, 2022
Rust language bindings for TensorFlow

TensorFlow Rust provides idiomatic Rust language bindings for TensorFlow. Notice: This project is still under active development and not guaranteed to

null 4.1k Jan 1, 2023
Machine learning crate for Rust

rustlearn A machine learning package for Rust. For full usage details, see the API documentation. Introduction This crate contains reasonably effectiv

Maciej Kula 547 Dec 28, 2022
Rust bindings for the C++ api of PyTorch.

tch-rs Rust bindings for the C++ api of PyTorch. The goal of the tch crate is to provide some thin wrappers around the C++ PyTorch api (a.k.a. libtorc

Laurent Mazare 2.3k Jan 1, 2023
个人的 rust 学习资料

?? 通知: 项目文档迁移到: https://github.com/higker/learn-rust learning-rust-zh 个人的 rust 学习资料 学习目录 目录 源代码地址 相关解析 第一个rust程序 https://github.com/higker/learning-ru

Jarvib Ding 16 Jun 21, 2022
Distributed compute platform implemented in Rust, and powered by Apache Arrow.

Ballista: Distributed Compute Platform Overview Ballista is a distributed compute platform primarily implemented in Rust, powered by Apache Arrow. It

Ballista 2.3k Jan 3, 2023
Tensors and differentiable operations (like TensorFlow) in Rust

autograd Differentiable operations and tensors backed by ndarray. Motivation Machine learning is one of the field where Rust lagging behind other lang

Ryo ASAKURA 403 Dec 25, 2022
Rust numeric library with R, MATLAB & Python syntax

Peroxide Rust numeric library contains linear algebra, numerical analysis, statistics and machine learning tools with R, MATLAB, Python like macros. W

Tae Geun Kim 351 Dec 29, 2022
A fast, safe and easy to use reinforcement learning framework in Rust.

RSRL (api) Reinforcement learning should be fast, safe and easy to use. Overview rsrl provides generic constructs for reinforcement learning (RL) expe

Thomas Spooner 139 Dec 13, 2022
Neural networks in Rust

deeplearn-rs Deep learning in Rust! This is my first shot at this. It's mostly just a proof of concept right now. The API will change. Status We have

Theodore DeRego 199 Oct 23, 2022