rust


Can't use lazy static integer constant for the size of an array


The following code gets the page size from sysconf to optimally read files from the filesystem. I am unable to create the buffer with the size:
lazy_static! {
static ref PAGE_SIZE: i64 = sysconf(SysconfVariable::ScPagesize).unwrap();
}
fn main() {
let mut buffer = [0; *PAGE_SIZE as usize];
}
Gives me:
error[E0080]: constant evaluation error
--> src/main.rs:6:30
|
6 | let mut buffer = [0; *PAGE_SIZE as usize];
| ^^^^^^^^^^ unimplemented constant expression: deref operation
I thought it is a operator priority problem and tried to wrap with it braces but the result still the same:
error[E0080]: constant evaluation error
--> src/main.rs:6:30
|
6 | let mut buffer = [0; (*(PAGE_SIZE)) as usize];
| ^^^^^^^^^^^^^^ unimplemented constant expression: deref operation
How to use the constant above for allocating a buffer?
This is not compile-time constant at all. Use vec! for anything that can't be determined compile-time:
let mut buffer = vec![0; *PAGE_SIZE as usize];
Currently there's no compiler level support for Variable-Length Arrays (VLA).

Related Links

How do I generate cargo docs for all platforms?
How to assign multiple existing variables from a tuple in Rust? [duplicate]
What is the usage of the asterisk symbol in Rust?
Convert Arc<RwLock> to &mut
Cargo build results in “No match for id”
Cargo fails because the peer certificate cannot be authenticated with given CA certificates on SLES11
How to group 'Option' assignments in Rust?
Exclude dependencies when running Clippy
How to create a new empty Tree
How to access a vector multiple times within an 'Option'?
Iterator on Option<Vec<>>
Literal out of range warning when iterating over all values of u8
How to write a trait that has a method returning a reference and implement it correctly?
Mismatched types when displaying a matrix with a for loop
How to have a struct field with the same mutability as the parent struct?
`if` condition remains borrowed in body [duplicate]

Categories

HOME
amazon-web-services
plesk
yahoo-weather-api
long-integer
enums
key
transactions
nsview
whmcs
biztalk-2010
elk-stack
haxe
u-boot
port
slide
fbloginview
createjs
orange-api
synthesis
closures
jqxgrid
hidden
infrared
conda
ava
firemonkey-style
opentext
pubxml
plyr
window-managers
ruby-daemons
oracleforms
bitbake
rust-cargo
creation
char-pointer
busboy
landscape
redgate
ftp-server
cargo
nanogallery
django-smart-selects
llvm-ir
sbjson
klee
pyttsx
minikube
adblock
viewmodel
libreoffice-writer
jgrapht
palindrome
test-data
ptvs
business-rules
gapi
ternary-operator
deviare
tsqlt
maven-release-plugin
meld
rails-engines
vimperator
lovefield
lowercase
calcite
bjam
knife
baseadapter
jcheckbox
encryption-symmetric
ildasm
smacss
xml-signature
tabris
libgcc
jini
csslint
gpu-programming
cloo
apportable
semicolon
onconfigurationchanged
struts2-json-plugin
audiotoolbox
clrprofiler
uitextfielddelegate
cakeyframeanimation
jdom
zotonic
struts2-s2hibernate
gamesalad
wcf-callbacks
boost-foreach
motodev-studio
filelock
sql-parametrized-query
tablet-pc
jmenu
aptitude
sscli
reliability
android-input-method
.net-services
browser-based
facebook-fbml
inversion

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App