devnagari 0.1.0

Code in Devanagari (Hindi/Sanskrit) — type aliases, macros, and keyword translation for Rust
Documentation
  • Coverage
  • 94.86%
    203 out of 214 items documented1 out of 122 items with examples
  • Size
  • Source code size: 88.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 52 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 2s Average build duration of successful builds.
  • all releases: 1m 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • xsmmaurya

devnagari

Crates.io Documentation License: MIT

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पूर्णांक for i32, पाठ for String, सूची<T> for Vec<T>, and 25+ more
  • Macro aliasesछापो! for println!, स्वरूप! for format!, 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

[dependencies]
devnagari = "0.1"

Then import the prelude:

use devnagari::prelude::*;

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 devnagari::prelude::*;

देव! {
    कार्य जोड़(: पूर्णांक,: पूर्णांक) -> पूर्णांक {+// क, ख are your identifiers — untouched
    }                  // पूर्णांक is a type alias — also untouched
}
// expands to: fn जोड़(क: i32, ख: i32) -> i32 { क + ख }

Block form vs attribute form

Block form — wrap multiple items:

देव! {
    संरचना बिंदु { x: दशमलव, y: दशमलव }

    क्रियान्वयन बिंदु {
        कार्य नया(x: दशमलव, y: दशमलव) -> स्वप्रकार {
            स्वप्रकार { x, y }
        }
    }
}

Attribute form — apply to a single item:

#[देव_attr]
संरचना बिंदु { x: दशमलव, y: दशमलव }

#[देव_attr]
क्रियान्वयन बिंदु {
    कार्य दूरी(&स्व, अन्य: &स्वप्रकार) -> दशमलव {
        मान dx = स्व.x - अन्य.x;
        मान dy = स्व.y - अन्य.y;
        (dx * dx + dy * dy).sqrt()
    }
}

ASCII aliases — for editors that struggle with Devanagari macro names:

dev! { ... }       // same as देव! { }
#[dev_attr]        // 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 devnagari::prelude::*;

देव! {
    संरचना विद्यार्थी {
        नाम: पाठ,
        अंक: पूर्णांक,
    }

    क्रियान्वयन विद्यार्थी {
        कार्य नया(नाम: पाठ, अंक: पूर्णांक) -> स्वप्रकार {
            स्वप्रकार { नाम, अंक }
        }

        कार्य श्रेणी(&स्व) -> &str {
            मिलान स्व.अंक {
                90..=100 => "उत्कृष्ट",
                75..=89  => "अच्छा",
                50..=74  => "सामान्य",
                _        => "अनुत्तीर्ण",
            }
        }
    }
}

fn main() {
    मान छात्र = विद्यार्थी::नया("अर्जुन".to_string(), 88);
    छापो!("{} की श्रेणी: {}", छात्र.नाम, छात्र.श्रेणी());
    // अर्जुन की श्रेणी: अच्छा
}

Hindi — enum, for loop, iterator extensions

use devnagari::prelude::*;

देव! {
    गणना दिन {
        सोमवार, मंगलवार, बुधवार, गुरुवार, शुक्रवार, शनिवार, रविवार,
    }

    कार्य सप्ताहांत_है(: &दिन) -> bool {
        मिलान द {
            दि::शनिवार | दि::रविवार => सत्य,
            _ => असत्य,
        }
    }
}

fn main() {
    मान संख्याएँ = सूची_बनाओ![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    मान सम: सूची<पूर्णांक> = संख्याएँ.iter()
        .copied()
        .छानो(|&x| x % 2 == 0)
        .संग्रह();
    छापो!("सम संख्याएँ: {:?}", सम);
    // सम संख्याएँ: [2, 4, 6, 8, 10]

    मान योग: पूर्णांक = सम.iter().copied().योग();
    छापो!("योगफल: {}", योग);
    // योगफल: 30
}

Sanskrit — struct, trait, impl

use devnagari::prelude::*;

देव! {
    लक्षण क्षेत्रफल {
        कर्म क्षेत्रफल(&आत्म) -> राशि;
    }

    रचना वृत्त { त्रिज्या: राशि }
    रचना आयत  { लम्बाई: राशि, चौड़ाई: राशि }

    साधन क्षेत्रफल कृते वृत्त {
        कर्म क्षेत्रफल(&आत्म) -> राशि {
            पाई * आत्म.त्रिज्या * आत्म.त्रिज्या
        }
    }

    साधन क्षेत्रफल कृते आयत {
        कर्म क्षेत्रफल(&आत्म) -> राशि {
            आत्म.लम्बाई * आत्म.चौड़ाई
        }
    }
}

fn main() {
    नियत व = वृत्त { त्रिज्या: पञ्च as f64 };
    नियत आ = आयत { लम्बाई: दश as f64, चौड़ाई: चतुर as f64 };

    वद!("वृत्त का क्षेत्रफल  = {:.2}",.क्षेत्रफल());
    वद!("आयत का क्षेत्रफल = {:.2}",.क्षेत्रफल());
}

Sanskrit — number constants, Option, Result

use devnagari::prelude::*;

fn main() {
    // Sanskrit numbers
    नियत परिणाम: अङ्क = एक + द्वि + त्रि + चतुर + पञ्च;
    वद!("१+२+३+४+५ = {}", परिणाम);   // 15

    // Option with Sanskrit variants
    नियत मान: सम्भव<अङ> = विद्यमान(पञ्च * दश);
    वद!("मान: {}", मान.या(नल));       // 50

    // Result with Sanskrit variants
    नियत फल: परिणा<अङ, &str> = सिद्ध(शत);
    निश्चय!(फल.ठीक_है());

    // Math constants
    वद!("π  = {:.6}", पाई);
    वद!("e  = {:.6}", प्रकृति);
    वद!("√2 = {:.6}", द्विमूल);
}

Async (with Tokio)

use devnagari::prelude::*;

देव! {
    अतुल्य कार्य डेटा_लाओ(url: &str) -> फल<, Box<गतिशील std::error::Error>> {
        मान प्रतिक्रिया = reqwest::get(url).प्रतीक्षा?;
        मान सामग्री = प्रतिक्रिया.text().प्रतीक्षा?;
        ठीक(सामग्री)
    }
}

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 the for keyword 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.