Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no_std support #337

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
make return type of supported_extensions based on feature
  • Loading branch information
CrazyboyQCD committed Feb 17, 2025
commit 5ce34c8cfa40e9620ac7589e8e000e6649e7efd1
7 changes: 7 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ compile_error!("\"hashbrown\" feature should be enabled in \"no_std\" environmen

use alloc::{boxed::Box, string::String, vec::Vec};
use core::{fmt::Debug, hash::Hash};

#[cfg(not(feature = "std"))]
use hashbrown::HashSet;
#[cfg(feature = "std")]
use std::collections::HashSet;

Expand Down Expand Up @@ -163,8 +166,12 @@ pub trait HasContext: __private::Sealed {
type TransformFeedback: Copy + Clone + Debug + Eq + Hash + Ord + PartialEq + PartialOrd;
type UniformLocation: Clone + Debug;

#[cfg(feature = "std")]
fn supported_extensions(&self) -> &HashSet<String>;

#[cfg(not(feature = "std"))]
fn supports_extension(&self) -> Vec<String>;

fn supports_debug(&self) -> bool;

fn version(&self) -> &Version;
Expand Down
6 changes: 6 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,16 @@ impl HasContext for Context {
type UniformLocation = NativeUniformLocation;
type TransformFeedback = NativeTransformFeedback;

#[cfg(feature = "std")]
fn supported_extensions(&self) -> &HashSet<String> {
&self.extensions
}

#[cfg(not(feature = "std"))]
fn supports_extension(&self) -> Vec<String> {
self.extensions.iter().map(|v| v.clone()).collect()
}

fn supports_debug(&self) -> bool {
if self.extensions.contains("GL_KHR_debug") {
// Supports extension (either GL or GL ES)
Expand Down
8 changes: 7 additions & 1 deletion src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1606,8 +1606,14 @@ impl HasContext for Context {
type UniformLocation = WebGlUniformLocation;
type TransformFeedback = WebTransformFeedbackKey;

#[cfg(feature = "std")]
fn supported_extensions(&self) -> &HashSet<String> {
&self.supported_extensions
&self.extensions
}

#[cfg(not(feature = "std"))]
fn supports_extension(&self) -> Vec<String> {
self.extensions.iter().map(|v| v.clone()).collect()
}

fn supports_debug(&self) -> bool {
Expand Down