devnagari
Write Rust in Devanagari — Hindi and Sanskrit both supported.
Devanagari Unicode characters have been valid Rust identifiers since Rust 1.53. This crate builds on that foundation to give you:
देव! { }— a proc-macro that translates Devanagari keywords (कार्य,यदि,मिलान…) into Rust keywords so the compiler accepts them- Type aliases —
पूर्णांकfori32,पाठforString,सूची<T>forVec<T>, and 25+ more - Macro aliases —
छापो!forprintln!,स्वरूप!forformat!, and more - Extension traits —
.लम्बाई(),.रिक्त_है(),.योग(),.छानो()and 30+ methods on standard types - Sanskrit vocabulary — classical Paninian/Vedic alternatives:
वर्ण(char),सूत्र(String),अङ्क(i32), number constantsएक–कोटि, and Sanskrit keyword synonyms
Installation
[]
= "0.1"
Then import the prelude:
use *;
How देव! { } works
Rust does not accept Devanagari as keywords (fn, let, if, etc.) but it does accept them as identifiers. देव! { } is a proc-macro that walks the token stream of its input and substitutes Devanagari keyword identifiers with their Rust equivalents before the compiler sees them.
कार्य → fn मान → let यदि → if मिलान → match
Everything that is not a keyword — your function names, variable names, struct fields, type names — passes through completely unchanged. So अर्जुन, क्षेत्रफल, विद्यार्थी remain exactly as you wrote them.
use *;
देव!
// expands to: fn जोड़(क: i32, ख: i32) -> i32 { क + ख }
Block form vs attribute form
Block form — wrap multiple items:
देव!
Attribute form — apply to a single item:
संरचना बिंदु
क्रियान्वयन बिंदु
ASCII aliases — for editors that struggle with Devanagari macro names:
dev! // same as देव! { }
// same as #[देव_attr]
Hindi keywords
These are the primary keyword mappings using everyday Hindi vocabulary.
| Devanagari | Rust | अर्थ |
|---|---|---|
कार्य |
fn |
function / work |
मान |
let |
value / binding |
परिवर्तनीय |
mut |
mutable |
यदि |
if |
if |
अन्यथा |
else |
otherwise |
जबतक |
while |
as long as |
प्रत्येक |
for |
for each |
चक्र |
loop |
cycle / loop |
मिलान |
match |
match / compare |
वापस |
return |
back / return |
रुको |
break |
stop |
जारी |
continue |
continue |
में |
in |
in |
संरचना |
struct |
structure |
गणना |
enum |
enumeration |
विशेषता |
trait |
characteristic |
क्रियान्वयन |
impl |
implementation |
जहाँ |
where |
where |
सार्वजनिक |
pub |
public |
खंड |
mod |
module / section |
उपयोग |
use |
use |
प्रकार |
type |
type |
स्थिरांक |
const |
constant |
स्थायी |
static |
static |
स्व |
self |
self |
स्वप्रकार |
Self |
Self (type) |
पितृ |
super |
parent / super |
मूल |
crate |
crate |
जैसे |
as |
as (cast / alias) |
अतुल्य |
async |
asynchronous |
प्रतीक्षा |
await |
wait / await |
चल |
move |
move closure |
गतिशील |
dyn |
dynamic dispatch |
असुरक्षित |
unsafe |
unsafe |
बाह्य |
extern |
external |
सत्य |
true |
true |
असत्य |
false |
false |
संदर्भ_बंध |
ref |
reference binding |
Sanskrit keywords
Classical Sanskrit alternatives that can be used instead of or alongside the Hindi keywords above. Both sets work inside the same देव! { } block — mix freely.
| Sanskrit | Rust | अर्थ |
|---|---|---|
कर्म |
fn |
action / deed (Bhagavad Gita) |
नियत |
let |
fixed / assigned |
विकारी |
mut |
subject to modification |
चेत् |
if |
if (classical conditional) |
यावत् |
while |
as long as (classical) |
आवर्तन |
loop |
repetition / cycling |
विराम |
break |
pause / stop |
अनुवर्तन |
continue |
following / proceeding |
निवृत्ति |
return |
returning / cessation |
कृते |
for |
for the purpose of (impl T for U) |
रचना |
struct |
creation / structure |
लक्षण |
trait |
characteristic (Paninian grammar) |
साधन |
impl |
means / implementation |
ध्रुव |
const |
fixed / pole star |
शाश्वत |
static |
eternal / unchanging |
यत्र |
where |
where (classical locative) |
आत्म |
self |
self (Vedantic concept) |
आत्मप्रकार |
Self |
Self type |
इव / यथा |
as |
like / as (Sanskrit comparative) |
असमकालिक |
async |
asynchronous |
प्रतीक्षण |
await |
act of waiting |
गमन |
move |
movement |
अरक्षित |
unsafe |
unprotected |
बाह्यिक |
extern |
external |
अंश |
mod |
part / portion |
Type aliases
Import via use devnagari::prelude::*.
Hindi type aliases
| Type alias | Rust type | अर्थ |
|---|---|---|
पूर्णांक |
i32 |
integer (default) |
दीर्घपूर्णांक |
i64 |
long integer |
महापूर्णांक |
i128 |
128-bit integer |
लघुपूर्णांक |
i8 |
small integer |
मध्यपूर्णांक |
i16 |
medium integer |
सूचकांक |
isize |
pointer-sized integer |
अष्टांक |
u8 |
unsigned 8-bit |
बाइट |
u8 |
byte (I/O alias) |
षोडशांक |
u16 |
unsigned 16-bit |
अचिह्नित |
u32 |
unsigned 32-bit |
दीर्घाचिह्नित |
u64 |
unsigned 64-bit |
आकार |
usize |
size / index type |
दशमलव |
f64 |
decimal (default float) |
लघुदशमलव |
f32 |
single-precision float |
पाठ |
String |
text (owned) |
अक्षर |
char |
character |
बूलियन |
bool |
boolean |
शून्य |
() |
unit / void |
सूची<T> |
Vec<T> |
list / vector |
कोश<K, V> |
HashMap<K, V> |
dictionary |
क्रमकोश<K, V> |
BTreeMap<K, V> |
ordered dictionary |
समुच्चय<T> |
HashSet<T> |
set |
द्विसिरासूची<T> |
VecDeque<T> |
double-ended queue |
विकल्प<T> |
Option<T> |
optional value |
फल<T, E> |
Result<T, E> |
result / outcome |
पिटारा<T> |
Box<T> |
heap box |
साझा<T> |
Arc<T> |
shared (thread-safe) |
आरसी<T> |
Rc<T> |
reference-counted |
कोशिका<T> |
Cell<T> |
interior mutable cell |
परिवर्तकोशिका<T> |
RefCell<T> |
runtime borrow cell |
ताला<T> |
Mutex<T> |
mutex lock |
पाठताला<T> |
RwLock<T> |
read-write lock |
Sanskrit type aliases
| Type alias | Rust type | अर्थ |
|---|---|---|
अङ्क |
i32 |
digit/numeral (Paninian) |
महाङ्क |
i64 |
great number |
राशि |
f64 |
quantity (Sanskrit math term) |
लघुराशि |
f32 |
small quantity |
वर्ण |
char |
phoneme/letter (Paninian) |
सूत्र |
String |
thread / formula / aphorism |
सत्यासत्य |
bool |
true-or-false (dvandva) |
परिमाण |
usize |
measure / quantity |
श्रेणी<T> |
Vec<T> |
series / row / sequence |
सम्भव<T> |
Option<T> |
possible / potential |
परिणाम<T, E> |
Result<T, E> |
outcome / result |
निघण्टु<K, V> |
HashMap<K, V> |
glossary / lexicon (Vedic) |
अनुक्रम<K, V> |
BTreeMap<K, V> |
ordered sequence |
वर्गः<T> |
HashSet<T> |
class / group / set |
पिटक<T> |
Box<T> |
basket / container |
संयोग<T> |
Arc<T> |
union / conjunction |
Constants & variants
Boolean, ordering, math
| Constant | Value | अर्थ |
|---|---|---|
सत्य |
true |
true |
असत्य |
false |
false |
कुछ(v) |
Some(v) |
a value is present |
रिक्त |
None |
no value |
ठीक(v) |
Ok(v) |
success |
त्रुटि(e) |
Err(e) |
error |
कम |
Ordering::Less |
less than |
बराबर |
Ordering::Equal |
equal |
अधिक |
Ordering::Greater |
greater than |
पाई |
3.14159… (π) |
pi |
प्रकृति |
2.71828… (e) |
Euler's number |
द्विमूल |
1.41421… (√2) |
square root of 2 |
अनंत |
f64::INFINITY |
infinity |
अपरिभाषित |
f64::NAN |
not a number |
Sanskrit variant aliases
| Constant | Value | अर्थ |
|---|---|---|
विद्यमान(v) |
Some(v) |
existing / present |
अविद्यमान |
None |
non-existing / absent |
सिद्ध(v) |
Ok(v) |
accomplished / proven |
दोष(e) |
Err(e) |
fault / defect |
Sanskrit number constants (i32)
| Constant | Value | Constant | Value |
|---|---|---|---|
नल |
0 |
एकादश |
11 |
एक |
1 |
द्वादश |
12 |
द्वि |
2 |
विंशति |
20 |
त्रि |
3 |
पञ्चाशत् |
50 |
चतुर |
4 |
शत |
100 |
पञ्च |
5 |
सहस्र |
1,000 |
षट |
6 |
लक्ष |
1,00,000 |
सप्त |
7 |
कोटि |
1,00,00,000 |
अष्ट |
8 |
||
नव |
9 |
||
दश |
10 |
usize variants: नल_आ, एक_आ, द्वि_आ, त्रि_आ, दश_आ, शत_आ, सहस्र_आ
Macros
Hindi macros
| Macro | Rust equivalent | विवरण |
|---|---|---|
छापो! |
println! |
Print line to stdout |
छाप! |
print! |
Print without newline |
त्रुटि_छापो! |
eprintln! |
Print line to stderr |
स्वरूप! |
format! |
Format into a String |
लिखो! |
write! |
Write formatted text to a writer |
पंक्तिलिखो! |
writeln! |
Write line to a writer |
जाँचो! |
dbg! |
Debug-print with file and line |
सूची_बनाओ! |
vec! |
Create a Vec |
घबराओ! |
panic! |
Panic with a message |
दावा! |
assert! |
Assert a condition |
समता_दावा! |
assert_eq! |
Assert equality |
असमता_दावा! |
assert_ne! |
Assert inequality |
करनाहै! |
todo! |
Mark as not yet implemented |
अपूर्ण! |
unimplemented! |
Mark as unimplemented |
अगम्य! |
unreachable! |
Mark as unreachable |
संयोग! |
concat! |
Concatenate literals |
पाठसंलग्न! |
include_str! |
Include file as &str |
बाइट_संलग्न! |
include_bytes! |
Include file as &[u8] |
पर्यावरण! |
env! |
Read env var at compile time |
विन्यास! |
cfg! |
Evaluate cfg condition |
नाम_पाठ! |
stringify! |
Stringify tokens |
Sanskrit macros
| Macro | Rust equivalent | अर्थ |
|---|---|---|
वद! |
println! |
speak / say |
उच्चार! |
print! |
pronounce / utter |
दोषवद! |
eprintln! |
speak error |
रचय! |
format! |
compose / create |
श्रेणी_रचय! |
vec! |
create a series |
भय! |
panic! |
fear / alarm |
निश्चय! |
assert! |
certainty / determination |
समत्व_निश्चय! |
assert_eq! |
equality certainty |
विषमत्व_निश्चय! |
assert_ne! |
inequality certainty |
परीक्षण! |
dbg! |
examination / testing |
कर्तव्य! |
todo! |
duty / what must be done |
असाधित! |
unimplemented! |
not yet accomplished |
अगम्य_पथ! |
unreachable! |
unreachable path |
Extension traits
All activated by use devnagari::prelude::*.
Vec<T> and [T]
| Method | Rust equivalent | विवरण |
|---|---|---|
.लम्बाई() |
.len() |
number of elements |
.रिक्त_है() |
.is_empty() |
true if empty |
.प्रथम() |
.first() |
first element (Option<&T>) |
.अंतिम() |
.last() |
last element (Option<&T>) |
.समाविष्ट(x) |
.contains(x) |
true if x is present |
String and str
| Method | Rust equivalent | विवरण |
|---|---|---|
.लम्बाई() |
.len() |
byte length |
.रिक्त_है() |
.is_empty() |
true if empty |
.अक्षर_संख्या() |
.chars().count() |
number of Unicode characters |
.बड़ेअक्षर() |
.to_uppercase() |
convert to uppercase |
.छोटेअक्षर() |
.to_lowercase() |
convert to lowercase |
.छाँटो() |
.trim() |
trim whitespace |
.समाविष्ट(pat) |
.contains(pat) |
substring check |
.से_शुरू(pat) |
.starts_with(pat) |
prefix check |
.पर_समाप्त(pat) |
.ends_with(pat) |
suffix check |
.बदलो(from, to) |
.replace(from, to) |
replace substring |
.विभाजित(pat) |
.split(pat).collect() |
split into Vec<&str> |
Iterator
| Method | Rust equivalent | विवरण |
|---|---|---|
.गणना() |
.count() |
count elements |
.संग्रह() |
.collect() |
collect into a collection |
.योग() |
.sum() |
sum all elements |
.गुणनफल() |
.product() |
product of all elements |
.अधिकतम() |
.max() |
maximum element |
.न्यूनतम() |
.min() |
minimum element |
.कोई(f) |
.any(f) |
true if any element matches |
.सभी(f) |
.all(f) |
true if all elements match |
.छानो(f) |
.filter(f) |
keep elements matching predicate |
.रूपांतर(f) |
.map(f) |
transform each element |
.समतलरूपांतर(f) |
.flat_map(f) |
transform and flatten |
.लो(n) |
.take(n) |
take first n elements |
.छोड़ो(n) |
.skip(n) |
skip first n elements |
.क्रमांकित() |
.enumerate() |
pair with index |
.झाँकने_योग्य() |
.peekable() |
make peekable |
.जोड़ो(other) |
.zip(other) |
zip two iterators |
.जोड़_दो(other) |
.chain(other) |
chain two iterators |
.खोजो(f) |
.find(f) |
first matching element |
.स्थान(f) |
.position(f) |
index of first match |
.संकुचन(init, f) |
.fold(init, f) |
reduce with accumulator |
.प्रत्येक_हेतु(f) |
.for_each(f) |
run closure on each element |
.उलटो() |
.rev() |
reverse (requires DoubleEndedIterator) |
Option<T>
| Method | Rust equivalent | विवरण |
|---|---|---|
.कुछ_है() |
.is_some() |
true if a value is present |
.रिक्त_है() |
.is_none() |
true if empty |
.खोलो() |
.unwrap() |
extract value or panic |
.या(default) |
.unwrap_or(d) |
extract or return default |
.रूपांतर(f) |
.map(f) |
transform the inner value |
Result<T, E>
| Method | Rust equivalent | विवरण |
|---|---|---|
.ठीक_है() |
.is_ok() |
true if success |
.त्रुटि_है() |
.is_err() |
true if error |
.खोलो() |
.unwrap() |
extract value or panic |
.या(default) |
.unwrap_or(d) |
extract or return default |
.रूपांतर(f) |
.map(f) |
transform the Ok value |
Examples
Hindi — struct, impl, match
use *;
देव!
Hindi — enum, for loop, iterator extensions
use *;
देव!
Sanskrit — struct, trait, impl
use *;
देव!
Sanskrit — number constants, Option, Result
use *;
Async (with Tokio)
use *;
देव!
Module structure
devnagari
├── prelude — re-exports everything; use devnagari::prelude::*
├── types — Hindi type aliases (पूर्णांक, पाठ, सूची, …)
├── sanskrit — Sanskrit type aliases, number constants, variant aliases
├── constants — boolean, ordering, math constants (पाई, अनंत, …)
├── macros — Hindi + Sanskrit macro aliases
└── traits — extension traits for Vec, str, String, Iterator, Option, Result
The companion crate devnagari_macros provides the देव!, dev!, #[देव_attr], and #[dev_attr] proc-macros. It is published separately but pulled in automatically as a dependency.
Notes
- Mixing Hindi and Sanskrit — both keyword sets work inside the same
देव! { }block. There is no conflict. - Your own names — identifiers that are not in the keyword map (
अर्जुन,क्षेत्रफल,विद्यार्थी, etc.) pass through untouched. - Regular Rust outside
देव!— you can mix regular Rust and Devanagari blocks freely in the same file. await— write.प्रतीक्षा(Hindi) or.प्रतीक्षण(Sanskrit) in place of.await.impl Trait for Type— useकृते(Sanskrit) orप्रत्येक(Hindi) for theforkeyword in this context.- ASCII fallback — if your editor or terminal cannot render Devanagari macro names, use
dev! { }and#[dev_attr]instead.
License
MIT — see LICENSE.